Skip to content

Commit 4725b54

Browse files
committed
🧪 Use stderr and stdout in processes test for conclusion
Uses the files created by the processes in the test for process abort to determine a pass or fail
1 parent 506fe19 commit 4725b54

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

‎tests/functional/test_run_execute_process.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pathlib
12
import time
23
import os
34
import sys
@@ -23,13 +24,15 @@ def test_monitor_processes(create_plain_run_offline: tuple[Run, dict]):
2324
@pytest.mark.executor
2425
def test_abort_all_processes(create_plain_run: tuple[Run, dict]) -> None:
2526
_run, _ = create_plain_run
26-
start_time = time.time()
2727
with tempfile.NamedTemporaryFile(suffix=".py") as temp_f:
2828
with open(temp_f.name, "w") as out_f:
2929
out_f.writelines([
3030
"import time\n",
31-
"while True:\n"
32-
" time.sleep(5)\n"
31+
"count = 0\n"
32+
"while True:\n",
33+
" print(count)\n"
34+
" time.sleep(1)\n"
35+
" count += 1"
3336
])
3437

3538
for i in range(1, 3):
@@ -39,9 +42,20 @@ def test_abort_all_processes(create_plain_run: tuple[Run, dict]) -> None:
3942
time.sleep(3)
4043

4144
_run.kill_all_processes()
42-
end_time = time.time()
4345

44-
assert end_time - start_time < 10, f"{end_time - start_time} >= 10"
46+
# Check the Python process did not error
47+
_out_err = pathlib.Path.cwd().glob("*process_*.err")
48+
for file in _out_err:
49+
with file.open() as in_f:
50+
assert not in_f.readlines()
51+
52+
# Now check the counter in the process was terminated
53+
# just beyond the sleep time
54+
_out_files = pathlib.Path.cwd().glob("*process_*.out")
55+
for file in _out_files:
56+
with file.open() as in_f:
57+
assert (lines := in_f.readlines())
58+
assert int(lines[0].strip()) < 4
4559

4660

4761
def test_processes_cwd(create_plain_run: dict[Run, dict]) -> None:

0 commit comments

Comments
 (0)