Skip to content

Commit de8bdc6

Browse files
authored
test: cancel notify - message immediately after 'Trapped' may not be digit (#294)
Signed-off-by: Morgan Epp <60796713+epmog@users.noreply.github.com>
1 parent 48fdc35 commit de8bdc6

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

hatch.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pre-install-commands = [
55

66
[envs.default.scripts]
77
sync = "pip install -r requirements-testing.txt"
8-
test = "pytest --cov-config pyproject.toml {args:test}"
8+
test = "pytest --cov-config pyproject.toml {args}"
99
typing = "mypy {args:src test}"
1010
style = [
1111
"ruff check {args:.}",

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ line-length = 100
137137

138138
[tool.pytest.ini_options]
139139
xfail_strict = false
140+
testpaths = [
141+
"test"
142+
]
140143
addopts = [
141144
"-rfEx",
142145
"--durations=5",

test/openjd/sessions/test_runner_base.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ def test_cancel_notify(
822822
# Test that NOTIFY_THEN_CANCEL first signals a SIGTERM and then a SIGKILL
823823

824824
# GIVEN
825+
proc_id: Optional[int] = None
825826
logger = build_logger(queue_handler)
826827
with NotifyingRunner(logger=logger, session_working_directory=tmp_path) as runner:
827828
python_app_loc = (
@@ -833,6 +834,11 @@ def test_cancel_notify(
833834
secs = 2 if not is_windows() else 5
834835
time.sleep(secs) # Give the process a little time to do something
835836
now = datetime.now(timezone.utc)
837+
838+
assert runner._process is not None
839+
assert runner._process._pid is not None
840+
proc_id = runner._process._pid
841+
836842
runner.cancel(time_limit=timedelta(seconds=2))
837843

838844
# THEN
@@ -849,9 +855,12 @@ def test_cancel_notify(
849855
messages = collect_queue_messages(message_queue)
850856
assert "Trapped" in messages
851857
trapped_idx = messages.index("Trapped")
858+
process_exit_idx = messages.index(
859+
f"Process pid {proc_id} exited with code: {runner.exit_code} (unsigned) / {hex(runner.exit_code)} (hex)"
860+
)
852861
# Should be at least one more number printed after the Trapped
853862
# to indicate that we didn't immediately terminate the script.
854-
assert messages[trapped_idx + 1].isdigit()
863+
assert any(msg.isdigit() for msg in messages[trapped_idx + 1 : process_exit_idx])
855864
# Didn't get to the end
856865
assert "Log from test 9" not in messages
857866
# Notification file exists

0 commit comments

Comments
 (0)