Fix race condition in FakeLogCollector async enumeration test#7300
Fix race condition in FakeLogCollector async enumeration test#7300stephentoub merged 3 commits intomainfrom
Conversation
… enumerator #2 Co-authored-by: stephentoub <[email protected]>
|
Co-authored-by: stephentoub <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR fixes a flaky test in FakeLogCollectorTests that was failing due to a race condition in concurrent async enumeration. The test creates two enumerators that process logs asynchronously, but the original code only waited for the first enumerator to complete before calling Clear(), which could cause the second enumerator to fail if it hadn't yet consumed the expected logs.
Changes:
- Added synchronization to ensure both concurrent async enumerators have consumed logs A and B before
Clear()is called - Used
TaskCompletionSource<bool>withRunContinuationsAsynchronouslyfor proper async coordination and .NET Framework compatibility
|
Adding my own summary as it took me a while to properly understand: The failure occurs in failing the assertion Test failure report |
Fix flaky test race condition in FakeLogCollectorTests
#2may not have consumed logs A and B before Clear() is called#2has processed both "A" and "B" (moveNextCounter == 2)Original prompt
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.
Microsoft Reviewers: Open in CodeFlow