Repository navigation
Fix flaky PhysicalFileProvider TokensFiredForOldAndNewNamesOnRename test - #130977
Conversation
The test waited a fixed 500ms after triggering the rename before asserting that the tokens had fired. PhysicalFilesWatcher.CancelToken cancels the token on a background thread-pool task, so under load (e.g. JitStress on slow arm64) the cancellation was not guaranteed to run within that window, causing the test to intermittently fail. Replace the fixed delay with the deterministic RegisterChangeCallback + TaskCompletionSource pattern already used by the sibling TokensFiredForNewDirectoryContentsOnRename test, awaiting the callbacks with a generous timeout instead. Fixes dotnet#129027 Co-authored-by: Copilot <[email protected]> Copilot-Session: 7e73cf9d-189a-4b07-96d7-156844a6d647
Extract the repeated 30-second token-fire timeout into a single s_maxWaitForTokenToFire field and convert the existing WaitTimeForTokenToFire and WaitTimeForTokenCallback constants to TimeSpan fields for consistency. No behavioral change. Co-authored-by: Copilot <[email protected]> Copilot-Session: 7e73cf9d-189a-4b07-96d7-156844a6d647
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @dotnet/area-extensions-filesystem |
There was a problem hiding this comment.
Pull request overview
This PR improves reliability of Microsoft.Extensions.FileProviders.Physical tests by removing a timing-based assertion from TokensFiredForOldAndNewNamesOnRename and replacing it with a deterministic callback + TaskCompletionSource wait (with a generous timeout). It also refactors the various timeout constants to TimeSpan fields for consistency and reuse.
Changes:
- Refactor test timeouts from
const intmillisecond values to sharedTimeSpanfields. - Fix
TokensFiredForOldAndNewNamesOnRenameflakiness by awaitingRegisterChangeCallbackcompletion (instead ofTask.Delay(500)). - Reuse a shared max-wait timeout (
s_maxWaitForTokenToFire) in the rename and polling tests.
Address review feedback: use TaskCompletionSource<bool> instead of TaskCompletionSource<object> for the token-fired signals, which keeps the intent explicit and avoids boxing. Apply the same change to the existing signals in TokensFiredForNewDirectoryContentsOnRename for consistency. The non-generic TaskCompletionSource is not used because the test project also targets .NET Framework, where it is unavailable. Co-authored-by: Copilot <[email protected]> Copilot-Session: 7e73cf9d-189a-4b07-96d7-156844a6d647
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Workflow state for the Holistic Review Orchestrator. {
"version": 5,
"last_dispatched_commit": "ccd435e01edb8d1f92a9d4eac902298d921d6d00",
"last_dispatched_base_ref": "main",
"last_dispatched_base_sha": "034f7f5c843988fd82ddfb8369b27c67ab986c86",
"last_reviewed_commit": "ccd435e01edb8d1f92a9d4eac902298d921d6d00",
"last_reviewed_base_ref": "main",
"last_reviewed_base_sha": "034f7f5c843988fd82ddfb8369b27c67ab986c86",
"last_recorded_worker_run_id": "29741184422",
"review_attempt_commit": "",
"review_attempt_base_ref": "",
"review_attempt_count": 0,
"max_review_attempts": 5,
"review_history_format": "holistic-review-disclosure-v1",
"review_history": [
{
"commit": "ccd435e01edb8d1f92a9d4eac902298d921d6d00",
"review_id": 4734863974
}
]
} |
There was a problem hiding this comment.
Holistic Review
Motivation: The TokensFiredForOldAndNewNamesOnRename test (issue #129027) waited a fixed 500ms after triggering a rename before asserting the tokens had fired. Because PhysicalFilesWatcher.CancelToken cancels tokens on a background thread-pool task, under load (e.g. JitStress on slow arm64) the cancellation could exceed that window, causing intermittent failures.
Approach: The fixed Task.Delay is replaced with the deterministic RegisterChangeCallback + TaskCompletionSource pattern already used by the sibling TokensFiredForNewDirectoryContentsOnRename test, awaiting both callbacks via Task.WhenAll(...).WaitAsync(s_maxWaitForTokenToFire) with a generous 30s timeout. A follow-up refactor extracts the repeated 30s timeout into a shared s_maxWaitForTokenToFire field and converts the existing WaitTimeForTokenToFire/WaitTimeForTokenCallback int constants into TimeSpan fields, and switches the token-fired TaskCompletionSource<object> signals to TaskCompletionSource<bool>.
Summary: This is a well-scoped, test-only change that correctly converts a timing-sensitive assertion into a deterministic wait. TaskCreationOptions.RunContinuationsAsynchronously is used to avoid running continuations inline on the watcher thread, matching best practice. The WaitAsync timeout preserves the test's ability to fail (rather than hang) if a token never fires, and the assertions on HasChanged still validate the observable behavior. The refactor is mechanical and non-behavioral; retaining TaskCompletionSource<bool> (rather than the non-generic form) is appropriately justified by .NET Framework targeting. No correctness, performance, or convention concerns.
LGTM.
Note
This review was generated by this repository's Holistic Review agentic workflow to complement the built-in Copilot review.
Generated by Holistic Review · 41.5 AIC · ⌖ 15.9 AIC · ⊞ 10K
Fixes #129027.
Problem
TokensFiredForOldAndNewNamesOnRenamewaited a fixed 500ms after triggering the rename before asserting that the tokens had fired.PhysicalFilesWatcher.CancelTokencancels the token on a background thread-pool task, so under load (e.g. JitStress on slow arm64) the cancellation was not guaranteed to run within that window, causing the test to intermittently fail.Fix
Replace the fixed delay with the deterministic
RegisterChangeCallback+TaskCompletionSourcepattern already used by the siblingTokensFiredForNewDirectoryContentsOnRenametest, awaiting the callbacks with a generous timeout instead.A second commit refactors the test's timeout values: the repeated 30-second token-fire timeout is extracted into a shared
s_maxWaitForTokenToFirefield, and the existingWaitTimeForTokenToFire/WaitTimeForTokenCallbackconstants are converted toTimeSpanfields for consistency. No behavioral change.Note
This PR was generated with the assistance of GitHub Copilot.