Skip to content

Commit e36b402

Browse files
authored
test: deflake test_signal_forwarding by waiting for handler installation (#6113)
1 parent ea29ab6 commit e36b402

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

tests/data/run_signals/test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
if output_file.exists():
1010
output_file.unlink()
1111

12+
ready_file = Path("ready.txt")
13+
if ready_file.exists():
14+
ready_file.unlink()
15+
1216

1317
def signal_handler(signum, frame):
1418
output_file.write_text(f"Signal handler called with signal {signum}\n")
@@ -20,6 +24,11 @@ def signal_handler(signum, frame):
2024

2125
signal.signal(signal.SIGINT, signal_handler)
2226

27+
# Signal to the test driver that the SIGINT handler is now installed. Without
28+
# this, the driver might deliver SIGINT before this line is reached, in which
29+
# case the default handler kills Python with exit code 130.
30+
ready_file.write_text("ready\n")
31+
2332
while True:
2433
print("Running...\n")
2534
time.sleep(1)

tests/integration_python/test_run_cli.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,21 @@ def test_signal_forwarding(pixi: Path, tmp_pixi_workspace: Path) -> None:
16941694
[pixi, "run", "--manifest-path", manifest, "start"], cwd=tmp_data_path
16951695
)
16961696

1697-
time.sleep(1) # wait for the process to start
1697+
# Wait for the child to install its SIGINT handler. Sleeping a fixed
1698+
# interval here is flaky on slower runners (notably macOS-aarch64): if the
1699+
# signal arrives before Python registers the handler, the default action
1700+
# kills the process with exit code 130 (128 + SIGINT).
1701+
ready_file = tmp_data_path.joinpath("ready.txt")
1702+
deadline = time.monotonic() + 30
1703+
while not ready_file.exists():
1704+
if process.poll() is not None:
1705+
raise AssertionError(
1706+
f"pixi exited before the task became ready (code {process.returncode})"
1707+
)
1708+
if time.monotonic() > deadline:
1709+
process.kill()
1710+
raise AssertionError("Timed out waiting for the task to install its SIGINT handler")
1711+
time.sleep(0.1)
16981712

16991713
# send a SIGINT to the process
17001714
process.send_signal(signal.SIGINT)

0 commit comments

Comments
 (0)