Skip to content

Fix flaky ScheduleTask_InlineContinuationDoesNotDeadlock test on net481#2957

Merged
martincostello merged 5 commits intoincrease-deadlock-test-timeoutfrom
copilot/refactor-scheduletask-test-timeout
Mar 4, 2026
Merged

Fix flaky ScheduleTask_InlineContinuationDoesNotDeadlock test on net481#2957
martincostello merged 5 commits intoincrease-deadlock-test-timeoutfrom
copilot/refactor-scheduletask-test-timeout

Conversation

Copy link

Copilot AI commented Mar 4, 2026

The ScheduleTask_InlineContinuationDoesNotDeadlock test was intermittently failing on net481 CI because the 1-second timeout was too tight. A previous attempted fix inadvertently broke the test's ability to detect the deadlock by moving the blocking wait outside the ExecuteSynchronously continuation — meaning the test passed even without TaskCreationOptions.RunContinuationsAsynchronously.

Details on the issue fix or feature implementation

  • Restored the correct test structure: secondTask.Wait(timeout) stays inside the ExecuteSynchronously continuation. This is what actually blocks the background processing thread when RunContinuationsAsynchronously is absent — causing the deadlock the test is designed to catch.
  • Increased timeout: 1s → 10s to reduce timing sensitivity on slow net481 CI agents.
  • Removed spurious #pragma warning disable xUnit1031 suppressions: xUnit1031 targets async Task test methods; it does not apply to void sync tests.

The test now correctly fails (after the full timeout) when TaskCreationOptions.RunContinuationsAsynchronously is removed from the TaskCompletionSource in ScheduledTaskExecutor, and passes with the current implementation.

Confirm the following

  • I started this PR by branching from the head of the default branch
  • I have targeted the PR to merge into the default branch
  • I have included unit tests for the issue/feature
  • I have successfully run a local build
Original prompt

Create a PR in App-vNext/Polly targeting branch increase-deadlock-test-timeout to fix the GitHub Actions job failure in run https://github.com/App-vNext/Polly/actions/runs/22670574047/job/65713291743?pr=2956.

Context:

  • The job failed on 2026-03-04 when running tests for net481.
  • Failing test: Polly.Core.Tests.CircuitBreaker.Controller.ScheduledTaskExecutorTests.ScheduleTask_InlineContinuationDoesNotDeadlock
  • Failure: continuationTask.Wait(timeout) expected true but was false, at test/Polly.Core.Tests/CircuitBreaker/Controller/ScheduledTaskExecutorTests.cs:line 150.
  • Current test code (at commit e6da2cc) uses timeout = TimeSpan.FromSeconds(1) and performs a nested blocking wait inside an inline continuation (ExecuteSynchronously).

Required changes:

  1. Refactor the test ScheduleTask_InlineContinuationDoesNotDeadlock in test/Polly.Core.Tests/CircuitBreaker/Controller/ScheduledTaskExecutorTests.cs to avoid nested blocking Wait() calls inside the synchronous continuation, while preserving the intent: scheduling a second task from within an inline continuation should not deadlock.
    • Use a deterministic pattern such as capturing the scheduled second task via TaskCompletionSource and awaiting/waiting outside the continuation.
    • Ensure the continuation still uses TaskContinuationOptions.ExecuteSynchronously to exercise the inline continuation scenario.
  2. Increase the timeout used by this test to reduce flakiness on net481 CI runs (e.g., 10 seconds), but keep the test reasonably fast.
  3. Ensure the test still passes across all target frameworks.

Notes:

  • The ScheduledTaskExecutor implementation is in src/Polly.Core/CircuitBreaker/Controller/ScheduledTaskExecutor.cs and uses a background processing task plus TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously).
  • Keep the change minimal and test-focused.

Acceptance criteria:

  • The updated test is less prone to timing flakiness.
  • No nested blocking waits inside the synchronous continuation.
  • Timeout increased and applied consistently.
  • CI job that previously failed should pass.

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

… nested blocking Wait

Co-authored-by: martincostello <1439341+martincostello@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix GitHub Actions job failure by refactoring test timeout Fix flaky ScheduleTask_InlineContinuationDoesNotDeadlock test on net481 Mar 4, 2026
Allow running CI for PRs targeting any branch, not just main.
@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.15%. Comparing base (e6da2cc) to head (54e0fbc).
⚠️ Report is 1 commits behind head on increase-deadlock-test-timeout.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@                       Coverage Diff                       @@
##           increase-deadlock-test-timeout    #2957   +/-   ##
===============================================================
  Coverage                           96.15%   96.15%           
===============================================================
  Files                                 309      309           
  Lines                                7128     7128           
  Branches                             1005     1005           
===============================================================
  Hits                                 6854     6854           
  Misses                                221      221           
  Partials                               53       53           
Flag Coverage Δ
linux 96.15% <ø> (ø)
macos 96.15% <ø> (ø)
windows 96.14% <ø> (-3.86%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…rect deadlock detection with increased timeout

Co-authored-by: martincostello <1439341+martincostello@users.noreply.github.com>
- Wait on both tasks with `Task.WaitAll()`.
- Suppress `xUnit1031`.
@martincostello martincostello marked this pull request as ready for review March 4, 2026 14:47
Copilot AI review requested due to automatic review settings March 4, 2026 14:47
@martincostello martincostello merged commit f3b04dd into increase-deadlock-test-timeout Mar 4, 2026
26 of 27 checks passed
@martincostello martincostello deleted the copilot/refactor-scheduletask-test-timeout branch March 4, 2026 14:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to fix intermittent failures of ScheduleTask_InlineContinuationDoesNotDeadlock on net481 by increasing the test timeout, and it also changes several GitHub Actions workflows to trigger on all pull requests (by removing base-branch filters).

Changes:

  • Increased the deadlock-detection test timeout from 1s to 10s and updated the final wait assertion.
  • Added a new xUnit1031 pragma suppression around a blocking wait in the test.
  • Removed pull_request.branches filters from multiple GitHub Actions workflows (broadening when they run).

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
test/Polly.Core.Tests/CircuitBreaker/Controller/ScheduledTaskExecutorTests.cs Increases timeout and changes how completion is waited for in the deadlock regression test.
.github/workflows/build.yml Removes pull_request base-branch filters, expanding workflow trigger scope.
.github/workflows/lint.yml Removes pull_request base-branch filters, expanding workflow trigger scope.
.github/workflows/mutation-tests.yml Removes pull_request base-branch filters, expanding workflow trigger scope.
.github/workflows/updater-approve.yml Removes pull_request base-branch filters, expanding workflow trigger scope.
.github/workflows/gh-pages.yml Removes pull_request base-branch filters, expanding workflow trigger scope.
.github/workflows/dependency-review.yml Removes pull_request base-branch filters, expanding workflow trigger scope.
.github/workflows/code-ql.yml Removes pull_request base-branch filters, expanding workflow trigger scope.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

4 participants