|
30 | 30 |
|
31 | 31 | BINARY_DISABLE_WEB_OPTION = "-nw"
|
32 | 32 | LOG_CHECKS_MAX_ATTEMPTS = 300
|
| 33 | +DEFAULT_TIMEOUT_WINDOW = -95 |
33 | 34 |
|
34 | 35 |
|
35 | 36 | @pytest.fixture
|
@@ -61,27 +62,29 @@ def start_binary_without_web_app():
|
61 | 62 |
|
62 | 63 | def start_binary_process(binary_options, output_file, err_file):
|
63 | 64 | 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 ''}", |
65 | 66 | shell=True,
|
66 | 67 | stdout=output_file,
|
67 | 68 | stderr=err_file,
|
68 | 69 | preexec_fn=os.setsid if not is_on_windows() else None)
|
69 | 70 |
|
70 | 71 |
|
71 | 72 | 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() |
85 | 88 |
|
86 | 89 |
|
87 | 90 | 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):
|
120 | 123 | return expected_content not in log_content
|
121 | 124 |
|
122 | 125 |
|
| 126 | +@pytest.mark.timeout(100 + DEFAULT_TIMEOUT_WINDOW) |
123 | 127 | def test_terms_endpoint(start_binary):
|
124 | 128 | multiple_checks(check_endpoint,
|
125 | 129 | max_attempts=100,
|
126 | 130 | endpoint_url="http://localhost:5001/terms",
|
127 | 131 | expected_code=200)
|
128 | 132 |
|
129 | 133 |
|
| 134 | +@pytest.mark.timeout(LOG_CHECKS_MAX_ATTEMPTS + DEFAULT_TIMEOUT_WINDOW) |
130 | 135 | def test_evaluation_state_created(start_binary_without_web_app):
|
131 | 136 | multiple_checks(check_logs_content,
|
132 | 137 | max_attempts=LOG_CHECKS_MAX_ATTEMPTS,
|
133 | 138 | expected_content="new state:")
|
134 | 139 |
|
135 | 140 |
|
| 141 | +@pytest.mark.timeout(LOG_CHECKS_MAX_ATTEMPTS + DEFAULT_TIMEOUT_WINDOW) |
136 | 142 | def test_logs_content_has_no_errors(start_binary_without_web_app):
|
137 | 143 | multiple_checks(check_logs_content,
|
138 | 144 | max_attempts=LOG_CHECKS_MAX_ATTEMPTS,
|
139 | 145 | expected_content="ERROR",
|
140 | 146 | should_appear=False)
|
141 | 147 |
|
142 | 148 |
|
| 149 | +@pytest.mark.timeout(LOG_CHECKS_MAX_ATTEMPTS + DEFAULT_TIMEOUT_WINDOW) |
143 | 150 | def test_balance_profitability_updated(start_binary_without_web_app):
|
144 | 151 | multiple_checks(check_logs_content,
|
145 | 152 | max_attempts=LOG_CHECKS_MAX_ATTEMPTS,
|
|
0 commit comments