Skip to content

TEST: Bound concurrent scenario resume with operation watchdogs - #4849

Open
Richard Lundeen (richlundeen) wants to merge 1 commit into
microsoft:mainfrom
richlundeen:test-scenario-resume-operation-watchdog
Open

Richard Lundeen (richlundeen) wants to merge 1 commit into
microsoft:mainfrom
richlundeen:test-scenario-resume-operation-watchdog

Conversation

@richlundeen

Copy link
Copy Markdown
Contributor

Description

test_concurrent_partial_failures_resume_without_duplicate_results used a 60 s whole-test pytest.mark.timeout as its deadlock guard, and saturated macOS runners slowed the run itself past it: run 47008045719, job 143918339549 recorded about 60.7 s of call time, timing out inside the first scenario.run_async(). Passing macOS calls take up to about 118 s, against about 1.5 s locally. This PR replaces the 60 s whole-test alarm with the repository-standard 300 s TEST_WATCHDOG_SECONDS hang watchdog on the rendezvous and on each run. That watchdog also excludes fixture setup and names the stuck phase.

  • The three-attack rendezvous is now awaited with wait_for_event_async, and each scenario.run_async() with wait_for_completion_async. Both come from tests/unit/async_utils.py and use the default TEST_WATCHDOG_SECONDS (300 s per phase).
  • A real deadlock still fails deterministically, and the TimeoutError names the stuck step: either the rendezvous never signaled readiness, or a run never completed. Neither helper cancels the run, so slow database reads are not interrupted, which keeps the reason TEST: avoid cancelling scenario resume for slow database reads #3138 removed asyncio.wait_for.
  • A finally block releases the test's gates, cancels only runs that are still pending, and joins the owned tasks.
  • @pytest.mark.timeout(60) becomes @pytest.mark.timeout(4 * TEST_WATCHDOG_SECONDS). It is now an outer backstop for hangs that block the event loop, sized above the test's four sequential watchdog waits, as other unit tests already do.
  • Assertions, mocks, concurrency settings, and product code are unchanged.

This follows the Correctness Test Timeouts guidance in test.instructions.md, which says hang-only bounds should use TEST_WATCHDOG_SECONDS. #4842 uses 120 s for a different set of tests. If maintainers would rather align this test with that, the change is a single constant.

The 60 s pytest-timeout on test_concurrent_partial_failures_resume_without_duplicate_results
measured the whole test, including sqlite fixture setup and initialize_async, so stalled macOS
runners hit it outside any deadlock. Bound the operations that can deadlock instead: the
three-attack rendezvous via wait_for_event_async and each scenario run via
wait_for_completion_async (TEST_WATCHDOG_SECONDS, no cancellation of the run). Release gates
and join owned runs in a finally block. The marker becomes an outer backstop for synchronous
hangs at 4 * TEST_WATCHDOG_SECONDS. Assertions and mocks are unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 4, 2026 23:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Repeated cancellation can let the test’s finally block exit before scenario-run tasks finish asynchronous cleanup because the waiter does not reliably drain them.

1 open issue
What changed in this PR

Updates PyRIT’s concurrent scenario-resume test to tolerate slow CI runners while retaining deadlock detection. Product code and existing assertions remain unchanged.

Changes:

  • Adds repository-standard watchdogs for rendezvous and scenario runs.
  • Adds gate release, task cancellation, and cleanup waits.
  • Raises the outer pytest timeout to accommodate per-operation watchdogs.
File Description
tests/​unit/​scenario/​core/​test_scenario_partial_results.py Updates watchdog bounds and task cleanup for the concurrent partial-failure resume test.

Review effort: Balanced

Comment on lines +1175 to +1177
await wait_for_completion_async(
future=asyncio.gather(*get_defined_tasks(first_run, resume_run), return_exceptions=True)
)

This branch has not been deployed

No deployments
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.

2 participants