Repository navigation
Investigate flaky WaitFor* timeouts on CI - #1952
Open
linkdotnet wants to merge 1 commit into
Open
linkdotnet wants to merge 1 commit into
linkdotnet wants to merge 1 commit into
Conversation
linkdotnet
force-pushed
the
fix/waitfor-threadpool-starvation
branch
from
October 19, 2026 21:12
1527b0e to
c288c39
Compare
linkdotnet
marked this pull request as ready for review
October 19, 2026 21:21
There was a problem hiding this comment.
🟡 Changes recommended
Timer-initialization failures can leave callers waiting indefinitely, and the scheduling changes need regression coverage.
2 open issues
What changed in this PR
Adds diagnostics and scheduling changes to investigate flaky bUnit WaitFor* timeouts on CI.
Changes:
- Logs elapsed time and thread-pool statistics on timeout.
- Defers timer startup and coordinates it with disposal.
- Raises test thread-pool minimums and initializes element-count state earlier.
| File | Description |
|---|---|
| tests/bunit.tests/Assembly.cs | Raises minimum worker threads for tests. |
| src/bunit/Extensions/WaitForHelpers/WaitForHelperLoggerExtensions.cs | Expands timeout diagnostics. |
| src/bunit/Extensions/WaitForHelpers/WaitForHelper.cs | Moves timer startup into dispatcher initialization and synchronizes disposal. |
| src/bunit/Extensions/WaitForHelpers/WaitForElementsHelper.cs | Uses a primary constructor to capture element count before base initialization. |
Review effort: Balanced
Comment on lines
+153
to
+156
| lock (checkPassedCompletionSource) | ||
| { | ||
| if (isDisposed || WaitTask.IsCompleted) | ||
| return; |
linkdotnet
force-pushed
the
fix/waitfor-threadpool-starvation
branch
from
October 20, 2026 05:37
c288c39 to
99e4806
Compare
Comment on lines
+254
to
+259
| dispatcherEntered.Wait(Xunit.TestContext.Current.CancellationToken); | ||
|
|
||
| var waitTask = cut.WaitForElementAsync("#notHere", TimeSpan.FromMilliseconds(5)); | ||
| await Task.Delay(50, Xunit.TestContext.Current.CancellationToken); | ||
| releaseDispatcher.Set(); | ||
| await blocker; |
- Start the WaitFor timeout timer only after the initial check ran on the renderer dispatcher; previously a busy dispatcher let the timer expire before any check executed. - Capture matchElementCount in WaitForElementsHelper before the base constructor starts the timer, which reads TimeoutErrorMessage. - Raise the thread pool floor in Bunit.Tests: parallel tests blocking pool threads starved the continuations they waited on. - Log configured vs actual elapsed time and thread pool load on timeout.
linkdotnet
force-pushed
the
fix/waitfor-threadpool-starvation
branch
from
October 20, 2026 06:26
99e4806 to
5c6510a
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Diagnostics for sporadic WaitFor* timeouts (e.g. runs 39277565989, 39276248124). Logs thread pool stats and actual vs configured elapsed time when a waiter times out.