Fix race condition in UnreliableL2Tests.WriteFailureInvisible#7075
Merged
stephentoub merged 3 commits intomainfrom Jan 8, 2026
Merged
Fix race condition in UnreliableL2Tests.WriteFailureInvisible#7075stephentoub merged 3 commits intomainfrom
stephentoub merged 3 commits intomainfrom
Conversation
… logs Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Investigate and fix flakiness in WriteFailureInvisible test
Fix race condition in UnreliableL2Tests.WriteFailureInvisible
Nov 21, 2025
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a flaky test (WriteFailureInvisible) that was intermittently failing in CI due to a race condition. The test verifies that L2 cache write failures are properly logged, but because these failures are logged asynchronously after a background write task completes, the original fixed 150ms delay was insufficient to reliably wait for logging to finish.
Key Changes:
- Added
WaitForLogsAsyncmethod toLogCollectorthat polls for expected log entries with a timeout instead of using fixed delays - Updated
WriteFailureInvisibletest to useWaitForLogsAsync(errorIds, TimeSpan.FromSeconds(5))instead ofTask.Delay(150)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LogCollector.cs | Added WaitForLogsAsync method that polls for log entries matching expected error IDs with configurable timeout, using thread-safe lock-based checking that mirrors the validation logic in AssertErrors |
| test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/UnreliableL2Tests.cs | Replaced unreliable fixed 150ms delay with WaitForLogsAsync call that polls for up to 5 seconds, ensuring logs are present before assertion |
ericstj
reviewed
Jan 6, 2026
test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LogCollector.cs
Show resolved
Hide resolved
ericstj
approved these changes
Jan 6, 2026
Member
ericstj
left a comment
There was a problem hiding this comment.
Looks good, just had a question that might simplify the method.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
The test was intermittently failing in CI because L2 write failures are logged asynchronously after the background write task completes, but the test used a fixed 150ms delay that didn't reliably wait for logging to finish.
Changes
WaitForLogsAsyncthat polls for expected log entries with timeout instead of guessing timingWaitForLogsAsync(errorIds, TimeSpan.FromSeconds(5))The polling logic matches
AssertErrorsexactly (count and order must match), ensuring test assertions see the same log state that will be verified.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Microsoft Reviewers: Open in CodeFlow