From ecc38995662e565475fdd85784e54919d664dec3 Mon Sep 17 00:00:00 2001 From: herklos Date: Thu, 18 Feb 2021 00:26:53 +0100 Subject: [PATCH 01/10] [CI] Add binary run tests --- .github/workflows/main.yml | 67 +++++++++++++++++++++++++++++++- .gitignore | 5 ++- dev_requirements.txt | 2 + tests/__init__.py | 46 ++++++++++++++++++++++ tests/test_binary.py | 78 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 dev_requirements.txt create mode 100644 tests/__init__.py create mode 100644 tests/test_binary.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index afef032..d47174c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -90,10 +90,72 @@ jobs: path: OctoBot/dist/OctoBot_windows.exe if-no-files-found: error + test: + name: ${{ matrix.os }}${{ matrix.arch }} - Python 3.8 - test + needs: + - build + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ macos-latest, windows-latest, ubuntu-latest ] + arch: [ x64 ] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: '3.8.x' + architecture: ${{ matrix.arch }} + + - name: Install dependencies + run: pip install -r dev_requirements.txt -r requirements.txt + + - name: Download Windows x64 artifact + if: matrix.os == 'windows-latest' + uses: actions/download-artifact@v2 + with: + name: OctoBot_windows_x64 + path: OctoBot_windows_x64.exe + + - name: Test OctoBot Binary on Windows + if: matrix.os == 'windows-latest' + run: | + pytest tests + + - name: Download Linux x64 artifact + if: matrix.os == 'ubuntu-latest' + uses: actions/download-artifact@v2 + with: + name: OctoBot_ubuntu-latest_x64 + path: OctoBot_linux_x64 + + - name: Test OctoBot Binary on Linux + if: matrix.os == 'ubuntu-latest' + run: | + chmod +x OctoBot_linux_x64 + pytest tests + + - name: Download MacOs x64 artifact + if: matrix.os == 'macos-latest' + uses: actions/download-artifact@v2 + with: + name: OctoBot_macos-latest_x64 + path: OctoBot_macos_x64 + + - name: Test OctoBot Binary on MacOs + if: matrix.os == 'macos-latest' + run: | + chmod +x OctoBot_macos_x64 + pytest tests + create-release: name: Create Release if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') - needs: builds + needs: + - build + - test runs-on: ubuntu-latest outputs: release-url-output: ${{ steps.create_release.outputs.upload_url }} @@ -199,7 +261,8 @@ jobs: name: Notify runs-on: ubuntu-latest needs: - - builds + - build + - test if: ${{ failure() }} steps: diff --git a/.gitignore b/.gitignore index 0872ba2..cdf9966 100644 --- a/.gitignore +++ b/.gitignore @@ -97,4 +97,7 @@ venv.bak/ # mypy .mypy_cache/ -\.idea/ +.idea +tentacles +user +logs diff --git a/dev_requirements.txt b/dev_requirements.txt new file mode 100644 index 0000000..547de5c --- /dev/null +++ b/dev_requirements.txt @@ -0,0 +1,2 @@ +pytest +requests diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..f71c4a5 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,46 @@ +# Drakkar-Software OctoBot-Binary +# Copyright (c) Drakkar-Software, All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3.0 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. +import os +import platform +import shutil + + +def get_binary_file_path() -> str: + if platform.system() == "Windows": + return "OctoBot_windows_x64.exe" + elif platform.system() == "Darwin": + return "./OctoBot_macos_x64" + else: + return "./OctoBot_linux_x64" + + +def delete_folder_if_exists(folder_path): + if os.path.exists(folder_path) and os.path.isdir(folder_path): + shutil.rmtree(folder_path) + + +def clear_octobot_previous_folders(): + for folder_path in [ + "logs", + "tentacles", + "user" + ]: + delete_folder_if_exists(folder_path) + + +def get_log_file_content(log_file_path="logs/OctoBot.log"): + with open(log_file_path, "r") as log_file: + return log_file.read() diff --git a/tests/test_binary.py b/tests/test_binary.py new file mode 100644 index 0000000..800de92 --- /dev/null +++ b/tests/test_binary.py @@ -0,0 +1,78 @@ +# Drakkar-Software OctoBot-Binary +# Copyright (c) Drakkar-Software, All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3.0 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. +import logging +import os +import signal +import subprocess +from tempfile import TemporaryFile + +import requests +import time + +import pytest + +from tests import get_binary_file_path, clear_octobot_previous_folders, get_log_file_content + +logger = logging.getLogger() +logger.setLevel(logging.DEBUG) + + +@pytest.fixture +def start_binary(): + clear_octobot_previous_folders() + with TemporaryFile() as output, TemporaryFile() as err: + binary_process = subprocess.Popen(get_binary_file_path(), + shell=True, + stdout=output, + stderr=err, + preexec_fn=os.setsid) + logger.debug("Starting binary process...") + yield + logger.info(output.read()) + errors = err.read() + if errors: + logger.error(errors) + raise ValueError(f"Error happened during process execution : {errors}") + logger.debug("Killing binary process...") + os.killpg(os.getpgid(binary_process.pid), signal.SIGTERM) # Send the signal to all the process groups + + +def test_version_endpoint(start_binary): + max_attempts = 10 + attempt = 1 + while max_attempts >= attempt > 0: + try: + requests.get('http://localhost:5001/version') + attempt = -1 # success + except requests.exceptions.ConnectionError: + logger.warning(f"Failed to get http://localhost/version, retrying ({attempt}/{max_attempts})...") + attempt += 1 + time.sleep(1) + assert attempt <= max_attempts + + +def test_evaluation_state_created(start_binary): + time.sleep(10) + log_content = get_log_file_content() + logger.debug(log_content) + assert "new state:" in log_content + + +def test_logs_content_has_no_errors(start_binary): + time.sleep(10) + log_content = get_log_file_content() + logger.debug(log_content) + assert "ERROR" not in log_content From c65f7c0a257b016ef61378c4e95190a52cd2c4d1 Mon Sep 17 00:00:00 2001 From: herklos Date: Thu, 18 Feb 2021 20:51:47 +0100 Subject: [PATCH 02/10] [Tests] Fix Windows process killing --- tests/__init__.py | 6 +++++- tests/test_binary.py | 13 ++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index f71c4a5..8941ef2 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -18,8 +18,12 @@ import shutil +def is_on_windows(): + return platform.system() == "Windows" + + def get_binary_file_path() -> str: - if platform.system() == "Windows": + if is_on_windows(): return "OctoBot_windows_x64.exe" elif platform.system() == "Darwin": return "./OctoBot_macos_x64" diff --git a/tests/test_binary.py b/tests/test_binary.py index 800de92..c2b531e 100644 --- a/tests/test_binary.py +++ b/tests/test_binary.py @@ -19,12 +19,13 @@ import subprocess from tempfile import TemporaryFile +import platform import requests import time import pytest -from tests import get_binary_file_path, clear_octobot_previous_folders, get_log_file_content +from tests import get_binary_file_path, clear_octobot_previous_folders, get_log_file_content, is_on_windows logger = logging.getLogger() logger.setLevel(logging.DEBUG) @@ -38,7 +39,7 @@ def start_binary(): shell=True, stdout=output, stderr=err, - preexec_fn=os.setsid) + preexec_fn=os.setsid if not is_on_windows() else None) logger.debug("Starting binary process...") yield logger.info(output.read()) @@ -47,7 +48,13 @@ def start_binary(): logger.error(errors) raise ValueError(f"Error happened during process execution : {errors}") logger.debug("Killing binary process...") - os.killpg(os.getpgid(binary_process.pid), signal.SIGTERM) # Send the signal to all the process groups + if is_on_windows(): + binary_process.kill() + else: + try: + os.killpg(os.getpgid(binary_process.pid), signal.SIGTERM) # Send the signal to all the process groups + except ProcessLookupError: + binary_process.kill() def test_version_endpoint(start_binary): From 71ff383f4a853be8fbcfc6475bc5f414ac5272e5 Mon Sep 17 00:00:00 2001 From: herklos Date: Thu, 18 Feb 2021 20:58:58 +0100 Subject: [PATCH 03/10] [Tests] Add disable web interface option --- tests/test_binary.py | 59 +++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/tests/test_binary.py b/tests/test_binary.py index c2b531e..f700601 100644 --- a/tests/test_binary.py +++ b/tests/test_binary.py @@ -30,31 +30,50 @@ logger = logging.getLogger() logger.setLevel(logging.DEBUG) +BINARY_DISABLE_WEB_OPTION = "-nw" + @pytest.fixture def start_binary(): clear_octobot_previous_folders() with TemporaryFile() as output, TemporaryFile() as err: - binary_process = subprocess.Popen(get_binary_file_path(), - shell=True, - stdout=output, - stderr=err, - preexec_fn=os.setsid if not is_on_windows() else None) - logger.debug("Starting binary process...") + binary_process = create_binary("", output, err) + yield + terminate_binary(binary_process, output, err) + + +@pytest.fixture +def start_binary_without_web_app(): + clear_octobot_previous_folders() + with TemporaryFile() as output, TemporaryFile() as err: + binary_process = create_binary(BINARY_DISABLE_WEB_OPTION, output, err) yield - logger.info(output.read()) - errors = err.read() - if errors: - logger.error(errors) - raise ValueError(f"Error happened during process execution : {errors}") - logger.debug("Killing binary process...") - if is_on_windows(): + terminate_binary(binary_process, output, err) + + +def create_binary(binary_options, output_file, err_file): + logger.debug("Starting binary process...") + return subprocess.Popen(f"{get_binary_file_path()} {binary_options}", + shell=True, + stdout=output_file, + stderr=err_file, + preexec_fn=os.setsid if not is_on_windows() else None) + + +def terminate_binary(binary_process, output_file, err_file): + logger.info(output_file.read()) + errors = err_file.read() + if errors: + logger.error(errors) + raise ValueError(f"Error happened during process execution : {errors}") + logger.debug("Killing binary process...") + if is_on_windows(): + binary_process.kill() + else: + try: + os.killpg(os.getpgid(binary_process.pid), signal.SIGTERM) # Send the signal to all the process groups + except ProcessLookupError: binary_process.kill() - else: - try: - os.killpg(os.getpgid(binary_process.pid), signal.SIGTERM) # Send the signal to all the process groups - except ProcessLookupError: - binary_process.kill() def test_version_endpoint(start_binary): @@ -71,14 +90,14 @@ def test_version_endpoint(start_binary): assert attempt <= max_attempts -def test_evaluation_state_created(start_binary): +def test_evaluation_state_created(start_binary_without_web_app): time.sleep(10) log_content = get_log_file_content() logger.debug(log_content) assert "new state:" in log_content -def test_logs_content_has_no_errors(start_binary): +def test_logs_content_has_no_errors(start_binary_without_web_app): time.sleep(10) log_content = get_log_file_content() logger.debug(log_content) From 7d5987076cab7dcebba1038163bb5ec21ccea0cf Mon Sep 17 00:00:00 2001 From: herklos Date: Thu, 18 Feb 2021 21:02:56 +0100 Subject: [PATCH 04/10] [Tests] Add balance profitability update --- tests/test_binary.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_binary.py b/tests/test_binary.py index f700601..cdc9a24 100644 --- a/tests/test_binary.py +++ b/tests/test_binary.py @@ -102,3 +102,10 @@ def test_logs_content_has_no_errors(start_binary_without_web_app): log_content = get_log_file_content() logger.debug(log_content) assert "ERROR" not in log_content + + +def test_balance_profitability_updated(start_binary_without_web_app): + time.sleep(10) + log_content = get_log_file_content() + logger.debug(log_content) + assert "BALANCE PROFITABILITY :" in log_content From 1ee665134ac808af54560a5d94476f0e9c1234b5 Mon Sep 17 00:00:00 2001 From: herklos Date: Thu, 18 Feb 2021 21:25:46 +0100 Subject: [PATCH 05/10] [Tests] Fix binary path --- .github/workflows/main.yml | 4 ++-- tests/__init__.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d47174c..07163e7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -134,7 +134,7 @@ jobs: - name: Test OctoBot Binary on Linux if: matrix.os == 'ubuntu-latest' run: | - chmod +x OctoBot_linux_x64 + chmod +x OctoBot_linux_x64/OctoBot_ubuntu-latest_x64 pytest tests - name: Download MacOs x64 artifact @@ -147,7 +147,7 @@ jobs: - name: Test OctoBot Binary on MacOs if: matrix.os == 'macos-latest' run: | - chmod +x OctoBot_macos_x64 + chmod +x OctoBot_macos_x64/OctoBot_macos-latest_x64 pytest tests create-release: diff --git a/tests/__init__.py b/tests/__init__.py index 8941ef2..fde07bf 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -24,11 +24,11 @@ def is_on_windows(): def get_binary_file_path() -> str: if is_on_windows(): - return "OctoBot_windows_x64.exe" + return "OctoBot_windows_x64.exe/OctoBot_windows.exe" elif platform.system() == "Darwin": - return "./OctoBot_macos_x64" + return "./OctoBot_macos_x64/OctoBot_macos-latest_x64" else: - return "./OctoBot_linux_x64" + return "./OctoBot_linux_x64/OctoBot_ubuntu-latest_x64" def delete_folder_if_exists(folder_path): From 1aa87665cc0293043215fedbc5575251936e8d6d Mon Sep 17 00:00:00 2001 From: Herklos Date: Thu, 4 Mar 2021 10:30:52 +0100 Subject: [PATCH 06/10] [Tests] Update sleep time to read logs content --- .github/workflows/main.yml | 8 ++-- tests/__init__.py | 16 ++++--- tests/test_binary.py | 95 ++++++++++++++++++++++++++------------ 3 files changed, 79 insertions(+), 40 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 07163e7..32ba7a5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,7 @@ name: OctoBot-Binary-CI on: push jobs: - builds: + build: name: ${{ matrix.os }} - ${{ matrix.arch }} - Python 3.8 - build runs-on: ${{ matrix.os }} strategy: @@ -59,7 +59,7 @@ jobs: env: GH_REPO: Drakkar-Software/OctoBot-Tentacles OCTOBOT_GH_REPO: https://github.com/Drakkar-Software/OctoBot.git - OCTOBOT_DEFAULT_BRANCH: dev + OCTOBOT_DEFAULT_BRANCH: master OCTOBOT_REPOSITORY_DIR: OctoBot NLTK_DATA: nltk_data BUILD_ARCH: ${{ matrix.arch }} @@ -70,7 +70,7 @@ jobs: env: GH_REPO: Drakkar-Software/OctoBot-Tentacles OCTOBOT_GH_REPO: https://github.com/Drakkar-Software/OctoBot.git - OCTOBOT_DEFAULT_BRANCH: dev + OCTOBOT_DEFAULT_BRANCH: master OCTOBOT_REPOSITORY_DIR: OctoBot NLTK_DATA: nltk_data run: .\build_scripts\windows.ps1 @@ -122,7 +122,7 @@ jobs: - name: Test OctoBot Binary on Windows if: matrix.os == 'windows-latest' run: | - pytest tests + pytest tests --full-trace - name: Download Linux x64 artifact if: matrix.os == 'ubuntu-latest' diff --git a/tests/__init__.py b/tests/__init__.py index fde07bf..7f9cac8 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -37,12 +37,16 @@ def delete_folder_if_exists(folder_path): def clear_octobot_previous_folders(): - for folder_path in [ - "logs", - "tentacles", - "user" - ]: - delete_folder_if_exists(folder_path) + try: + for folder_path in [ + "logs", + "tentacles", + "user" + ]: + delete_folder_if_exists(folder_path) + except PermissionError: + # Windows file conflict + pass def get_log_file_content(log_file_path="logs/OctoBot.log"): diff --git a/tests/test_binary.py b/tests/test_binary.py index cdc9a24..9b60b5c 100644 --- a/tests/test_binary.py +++ b/tests/test_binary.py @@ -19,39 +19,47 @@ import subprocess from tempfile import TemporaryFile -import platform +import pytest import requests import time -import pytest - from tests import get_binary_file_path, clear_octobot_previous_folders, get_log_file_content, is_on_windows logger = logging.getLogger() logger.setLevel(logging.DEBUG) BINARY_DISABLE_WEB_OPTION = "-nw" +LOG_CHECKS_MAX_ATTEMPTS = 300 @pytest.fixture def start_binary(): clear_octobot_previous_folders() with TemporaryFile() as output, TemporaryFile() as err: - binary_process = create_binary("", output, err) - yield - terminate_binary(binary_process, output, err) + binary_process = start_binary_process("", output, err) + try: + yield + except Exception: + pass + finally: + terminate_binary(binary_process, output, err) @pytest.fixture def start_binary_without_web_app(): clear_octobot_previous_folders() with TemporaryFile() as output, TemporaryFile() as err: - binary_process = create_binary(BINARY_DISABLE_WEB_OPTION, output, err) - yield - terminate_binary(binary_process, output, err) + binary_process = start_binary_process(BINARY_DISABLE_WEB_OPTION, output, err) + logger.debug(err.read()) + try: + yield + except Exception: + pass + finally: + terminate_binary(binary_process, output, err) -def create_binary(binary_options, output_file, err_file): +def start_binary_process(binary_options, output_file, err_file): logger.debug("Starting binary process...") return subprocess.Popen(f"{get_binary_file_path()} {binary_options}", shell=True, @@ -68,7 +76,7 @@ def terminate_binary(binary_process, output_file, err_file): raise ValueError(f"Error happened during process execution : {errors}") logger.debug("Killing binary process...") if is_on_windows(): - binary_process.kill() + os.kill(binary_process.pid, signal.CTRL_C_EVENT) else: try: os.killpg(os.getpgid(binary_process.pid), signal.SIGTERM) # Send the signal to all the process groups @@ -76,36 +84,63 @@ def terminate_binary(binary_process, output_file, err_file): binary_process.kill() -def test_version_endpoint(start_binary): - max_attempts = 10 +def multiple_checks(check_method, sleep_time=1, max_attempts=10, **kwargs): attempt = 1 while max_attempts >= attempt > 0: try: - requests.get('http://localhost:5001/version') - attempt = -1 # success - except requests.exceptions.ConnectionError: - logger.warning(f"Failed to get http://localhost/version, retrying ({attempt}/{max_attempts})...") + result = check_method(**kwargs) + if result: # success + return + except Exception as e: + logger.warning(f"Check ({attempt}/{max_attempts}) failed : {e}") + finally: attempt += 1 - time.sleep(1) - assert attempt <= max_attempts + try: + time.sleep(sleep_time) + except KeyboardInterrupt: + # Fails when windows is stopping binary + pass + assert False # fail -def test_evaluation_state_created(start_binary_without_web_app): - time.sleep(10) +def check_endpoint(endpoint_url, expected_code): + try: + result = requests.get(endpoint_url) + return result.status_code == expected_code + except requests.exceptions.ConnectionError: + logger.warning(f"Failed to get {endpoint_url}") + return False + + +def check_logs_content(expected_content: str, should_appear: bool = True): log_content = get_log_file_content() logger.debug(log_content) - assert "new state:" in log_content + if should_appear: + return expected_content in log_content + return expected_content not in log_content + + +def test_terms_endpoint(start_binary): + multiple_checks(check_endpoint, + max_attempts=100, + endpoint_url="http://localhost:5001/terms", + expected_code=200) + + +def test_evaluation_state_created(start_binary_without_web_app): + multiple_checks(check_logs_content, + max_attempts=LOG_CHECKS_MAX_ATTEMPTS, + expected_content="new state:") def test_logs_content_has_no_errors(start_binary_without_web_app): - time.sleep(10) - log_content = get_log_file_content() - logger.debug(log_content) - assert "ERROR" not in log_content + multiple_checks(check_logs_content, + max_attempts=LOG_CHECKS_MAX_ATTEMPTS, + expected_content="ERROR", + should_appear=False) def test_balance_profitability_updated(start_binary_without_web_app): - time.sleep(10) - log_content = get_log_file_content() - logger.debug(log_content) - assert "BALANCE PROFITABILITY :" in log_content + multiple_checks(check_logs_content, + max_attempts=LOG_CHECKS_MAX_ATTEMPTS, + expected_content="BALANCE PROFITABILITY :") From 91768954271e4de7a208e5f8d9b4116c4b4cc504 Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Thu, 4 Mar 2021 21:23:03 +0100 Subject: [PATCH 07/10] [CI] Fix nltk_data env variable usage --- build_scripts/windows.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_scripts/windows.ps1 b/build_scripts/windows.ps1 index 57f5aab..f977c9f 100644 --- a/build_scripts/windows.ps1 +++ b/build_scripts/windows.ps1 @@ -6,7 +6,7 @@ python scripts/python_file_lister.py bin/octobot_packages_files.txt $env:OCTOBOT python scripts/insert_imports.py $env:OCTOBOT_REPOSITORY_DIR/octobot/cli.py Copy-Item bin $env:OCTOBOT_REPOSITORY_DIR -recurse cd $env:OCTOBOT_REPOSITORY_DIR -python ../scripts/fetch_nltk_data.py words $NLTK_DATA +python ../scripts/fetch_nltk_data.py words $env:NLTK_DATA python setup.py build_ext --inplace python -m PyInstaller bin/start.spec Rename-Item dist/OctoBot.exe OctoBot_windows.exe From b81f3cbfd7519171bfb6cc3ba5e259a57c545d28 Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Thu, 4 Mar 2021 23:04:29 +0100 Subject: [PATCH 08/10] [Tests] Fix windows tests and add timeout management --- dev_requirements.txt | 1 + tests/__init__.py | 2 +- tests/test_binary.py | 35 +++++++++++++++++++++-------------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/dev_requirements.txt b/dev_requirements.txt index 547de5c..d4603c2 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -1,2 +1,3 @@ pytest +pytest-timeout requests diff --git a/tests/__init__.py b/tests/__init__.py index 7f9cac8..19d8552 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -24,7 +24,7 @@ def is_on_windows(): def get_binary_file_path() -> str: if is_on_windows(): - return "OctoBot_windows_x64.exe/OctoBot_windows.exe" + return "OctoBot_windows_x64.exe\\OctoBot_windows.exe" elif platform.system() == "Darwin": return "./OctoBot_macos_x64/OctoBot_macos-latest_x64" else: diff --git a/tests/test_binary.py b/tests/test_binary.py index 9b60b5c..e86caec 100644 --- a/tests/test_binary.py +++ b/tests/test_binary.py @@ -30,6 +30,7 @@ BINARY_DISABLE_WEB_OPTION = "-nw" LOG_CHECKS_MAX_ATTEMPTS = 300 +DEFAULT_TIMEOUT_WINDOW = -95 @pytest.fixture @@ -61,7 +62,7 @@ def start_binary_without_web_app(): def start_binary_process(binary_options, output_file, err_file): logger.debug("Starting binary process...") - return subprocess.Popen(f"{get_binary_file_path()} {binary_options}", + return subprocess.Popen(f"{get_binary_file_path()}{f' {binary_options}' if binary_options else ''}", shell=True, stdout=output_file, stderr=err_file, @@ -69,19 +70,21 @@ def start_binary_process(binary_options, output_file, err_file): def terminate_binary(binary_process, output_file, err_file): - logger.info(output_file.read()) - errors = err_file.read() - if errors: - logger.error(errors) - raise ValueError(f"Error happened during process execution : {errors}") - logger.debug("Killing binary process...") - if is_on_windows(): - os.kill(binary_process.pid, signal.CTRL_C_EVENT) - else: - try: - os.killpg(os.getpgid(binary_process.pid), signal.SIGTERM) # Send the signal to all the process groups - except ProcessLookupError: - binary_process.kill() + try: + logger.info(output_file.read()) + errors = err_file.read() + if errors: + logger.error(errors) + raise ValueError(f"Error happened during process execution : {errors}") + finally: + logger.debug("Killing binary process...") + if is_on_windows(): + subprocess.call(["taskkill", "/F", "/IM", "OctoBot_windows.exe"]) + else: + try: + os.killpg(os.getpgid(binary_process.pid), signal.SIGTERM) # Send the signal to all the process groups + except ProcessLookupError: + binary_process.kill() def multiple_checks(check_method, sleep_time=1, max_attempts=10, **kwargs): @@ -120,6 +123,7 @@ def check_logs_content(expected_content: str, should_appear: bool = True): return expected_content not in log_content +@pytest.mark.timeout(100 + DEFAULT_TIMEOUT_WINDOW) def test_terms_endpoint(start_binary): multiple_checks(check_endpoint, max_attempts=100, @@ -127,12 +131,14 @@ def test_terms_endpoint(start_binary): expected_code=200) +@pytest.mark.timeout(LOG_CHECKS_MAX_ATTEMPTS + DEFAULT_TIMEOUT_WINDOW) def test_evaluation_state_created(start_binary_without_web_app): multiple_checks(check_logs_content, max_attempts=LOG_CHECKS_MAX_ATTEMPTS, expected_content="new state:") +@pytest.mark.timeout(LOG_CHECKS_MAX_ATTEMPTS + DEFAULT_TIMEOUT_WINDOW) def test_logs_content_has_no_errors(start_binary_without_web_app): multiple_checks(check_logs_content, max_attempts=LOG_CHECKS_MAX_ATTEMPTS, @@ -140,6 +146,7 @@ def test_logs_content_has_no_errors(start_binary_without_web_app): should_appear=False) +@pytest.mark.timeout(LOG_CHECKS_MAX_ATTEMPTS + DEFAULT_TIMEOUT_WINDOW) def test_balance_profitability_updated(start_binary_without_web_app): multiple_checks(check_logs_content, max_attempts=LOG_CHECKS_MAX_ATTEMPTS, From da2b75bafb8897c0cdee6787a1345e057c1b9e14 Mon Sep 17 00:00:00 2001 From: herklos Date: Tue, 9 Mar 2021 21:57:07 +0100 Subject: [PATCH 09/10] [CI] Fix test job name --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 32ba7a5..a990b59 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -91,7 +91,7 @@ jobs: if-no-files-found: error test: - name: ${{ matrix.os }}${{ matrix.arch }} - Python 3.8 - test + name: ${{ matrix.os }} - ${{ matrix.arch }} - Python 3.8 - test needs: - build runs-on: ${{ matrix.os }} From 1ddf20dfc900f2763975af955e6c5ee9aaa89877 Mon Sep 17 00:00:00 2001 From: Herklos Date: Tue, 13 Apr 2021 16:42:26 +0200 Subject: [PATCH 10/10] [CI] Fix downloaded assets name --- .github/workflows/main.yml | 4 ++-- tests/__init__.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a990b59..1eb08d3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -134,7 +134,7 @@ jobs: - name: Test OctoBot Binary on Linux if: matrix.os == 'ubuntu-latest' run: | - chmod +x OctoBot_linux_x64/OctoBot_ubuntu-latest_x64 + chmod +x OctoBot_linux_x64/OctoBot_x64 pytest tests - name: Download MacOs x64 artifact @@ -147,7 +147,7 @@ jobs: - name: Test OctoBot Binary on MacOs if: matrix.os == 'macos-latest' run: | - chmod +x OctoBot_macos_x64/OctoBot_macos-latest_x64 + chmod +x OctoBot_macos_x64/OctoBot_x64 pytest tests create-release: diff --git a/tests/__init__.py b/tests/__init__.py index 19d8552..0ef9e63 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -26,9 +26,9 @@ def get_binary_file_path() -> str: if is_on_windows(): return "OctoBot_windows_x64.exe\\OctoBot_windows.exe" elif platform.system() == "Darwin": - return "./OctoBot_macos_x64/OctoBot_macos-latest_x64" + return "./OctoBot_macos_x64/OctoBot_x64" else: - return "./OctoBot_linux_x64/OctoBot_ubuntu-latest_x64" + return "./OctoBot_linux_x64/OctoBot_x64" def delete_folder_if_exists(folder_path):