Skip to content

Fix: Timing-related issue with clean-shutdown tests.#233

Merged
griffinmilsap merged 1 commit intodevfrom
fix/shutdown-ready-sync
Mar 17, 2026
Merged

Fix: Timing-related issue with clean-shutdown tests.#233
griffinmilsap merged 1 commit intodevfrom
fix/shutdown-ready-sync

Conversation

@griffinmilsap
Copy link
Collaborator

Summary

This PR fixes a timing race in shutdown test orchestration that could cause inconsistent return codes in test_shutdown_exception_on_cancel.

Problem

tests/shutdown_runner.py emitted READY as soon as runner.running became True.
In some runs, that happened before the target task actually entered its execution loop.

As a result:

  • SIGINT could be sent too early
  • cancellation-path behavior under test might not be exercised
  • subprocess could exit 0 instead of a SIGINT code (130 / -SIGINT)

Changes

Updated tests/shutdown_runner.py to synchronize readiness with actual task start:

  • Added a module-scoped STARTED event.
  • Set STARTED at entry of each task used by shutdown tests:
    • BlockingDiskIO.blocked_read
    • BlockingSocket.blocked_recv
    • ExplodeOnCancel.explode
    • StubbornTask.ignore_cancel
  • Changed READY gate in watcher thread from:
    • runner.running
      to:
    • runner.running and STARTED.is_set()

Why this fix

This ensures signal injection only starts after the target task is truly active, making shutdown behavior tests deterministic and aligned with the scenario they are intended to validate.

Testing

  • pytest tests/test_clean_shutdown.py::test_shutdown_exception_on_cancel -q
  • pytest tests/test_clean_shutdown.py -q

Both pass consistently with this change.

@griffinmilsap griffinmilsap merged commit 198de90 into dev Mar 17, 2026
14 checks passed
@griffinmilsap griffinmilsap deleted the fix/shutdown-ready-sync branch March 17, 2026 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant