Skip to content

Commit b81f3cb

Browse files
Guillaume De Saint MartinHerklos
Guillaume De Saint Martin
authored andcommitted
[Tests] Fix windows tests and add timeout management
1 parent 9176895 commit b81f3cb

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

dev_requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pytest
2+
pytest-timeout
23
requests

tests/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def is_on_windows():
2424

2525
def get_binary_file_path() -> str:
2626
if is_on_windows():
27-
return "OctoBot_windows_x64.exe/OctoBot_windows.exe"
27+
return "OctoBot_windows_x64.exe\\OctoBot_windows.exe"
2828
elif platform.system() == "Darwin":
2929
return "./OctoBot_macos_x64/OctoBot_macos-latest_x64"
3030
else:

tests/test_binary.py

+21-14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
BINARY_DISABLE_WEB_OPTION = "-nw"
3232
LOG_CHECKS_MAX_ATTEMPTS = 300
33+
DEFAULT_TIMEOUT_WINDOW = -95
3334

3435

3536
@pytest.fixture
@@ -61,27 +62,29 @@ def start_binary_without_web_app():
6162

6263
def start_binary_process(binary_options, output_file, err_file):
6364
logger.debug("Starting binary process...")
64-
return subprocess.Popen(f"{get_binary_file_path()} {binary_options}",
65+
return subprocess.Popen(f"{get_binary_file_path()}{f' {binary_options}' if binary_options else ''}",
6566
shell=True,
6667
stdout=output_file,
6768
stderr=err_file,
6869
preexec_fn=os.setsid if not is_on_windows() else None)
6970

7071

7172
def terminate_binary(binary_process, output_file, err_file):
72-
logger.info(output_file.read())
73-
errors = err_file.read()
74-
if errors:
75-
logger.error(errors)
76-
raise ValueError(f"Error happened during process execution : {errors}")
77-
logger.debug("Killing binary process...")
78-
if is_on_windows():
79-
os.kill(binary_process.pid, signal.CTRL_C_EVENT)
80-
else:
81-
try:
82-
os.killpg(os.getpgid(binary_process.pid), signal.SIGTERM) # Send the signal to all the process groups
83-
except ProcessLookupError:
84-
binary_process.kill()
73+
try:
74+
logger.info(output_file.read())
75+
errors = err_file.read()
76+
if errors:
77+
logger.error(errors)
78+
raise ValueError(f"Error happened during process execution : {errors}")
79+
finally:
80+
logger.debug("Killing binary process...")
81+
if is_on_windows():
82+
subprocess.call(["taskkill", "/F", "/IM", "OctoBot_windows.exe"])
83+
else:
84+
try:
85+
os.killpg(os.getpgid(binary_process.pid), signal.SIGTERM) # Send the signal to all the process groups
86+
except ProcessLookupError:
87+
binary_process.kill()
8588

8689

8790
def multiple_checks(check_method, sleep_time=1, max_attempts=10, **kwargs):
@@ -120,26 +123,30 @@ def check_logs_content(expected_content: str, should_appear: bool = True):
120123
return expected_content not in log_content
121124

122125

126+
@pytest.mark.timeout(100 + DEFAULT_TIMEOUT_WINDOW)
123127
def test_terms_endpoint(start_binary):
124128
multiple_checks(check_endpoint,
125129
max_attempts=100,
126130
endpoint_url="http://localhost:5001/terms",
127131
expected_code=200)
128132

129133

134+
@pytest.mark.timeout(LOG_CHECKS_MAX_ATTEMPTS + DEFAULT_TIMEOUT_WINDOW)
130135
def test_evaluation_state_created(start_binary_without_web_app):
131136
multiple_checks(check_logs_content,
132137
max_attempts=LOG_CHECKS_MAX_ATTEMPTS,
133138
expected_content="new state:")
134139

135140

141+
@pytest.mark.timeout(LOG_CHECKS_MAX_ATTEMPTS + DEFAULT_TIMEOUT_WINDOW)
136142
def test_logs_content_has_no_errors(start_binary_without_web_app):
137143
multiple_checks(check_logs_content,
138144
max_attempts=LOG_CHECKS_MAX_ATTEMPTS,
139145
expected_content="ERROR",
140146
should_appear=False)
141147

142148

149+
@pytest.mark.timeout(LOG_CHECKS_MAX_ATTEMPTS + DEFAULT_TIMEOUT_WINDOW)
143150
def test_balance_profitability_updated(start_binary_without_web_app):
144151
multiple_checks(check_logs_content,
145152
max_attempts=LOG_CHECKS_MAX_ATTEMPTS,

0 commit comments

Comments
 (0)