extensions icon indicating copy to clipboard operation
extensions copied to clipboard

Fix race condition in UnreliableL2Tests.WriteFailureInvisible

Open Copilot opened this issue 1 month ago • 0 comments

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

  • LogCollector: Added WaitForLogsAsync that polls for expected log entries with timeout instead of guessing timing
  • UnreliableL2Tests: Replaced fixed delay with WaitForLogsAsync(errorIds, TimeSpan.FromSeconds(5))

The polling logic matches AssertErrors exactly (count and order must match), ensuring test assertions see the same log state that will be verified.

// Before: unreliable fixed delay
await l2.LastWrite;
await Task.Delay(150); // thread jitter caused failures
log.AssertErrors(errorIds);

// After: poll until logs appear or timeout
await l2.LastWrite;
await log.WaitForLogsAsync(errorIds, TimeSpan.FromSeconds(5));
log.AssertErrors(errorIds);
Original prompt

This test failed in CI. Please either investigate the flakiness and fix it, or disable the test if it's inherently flaky:

Microsoft.Extensions.Caching.Hybrid.Tests.UnreliableL2Tests.WriteFailureInvisible(writeBreak: AsynchronousYield, errorIds: [7])

Result Details Failed 39m ago on 642af2e5c000000 Duration0:00:00.673 Ownernot available Date started11/21/2025, 9:29:23 AM Date completed11/21/2025, 9:29:24 AM Failing since37m ago Failing since build20251121.17

Debug

Work items

Attachments

History

1ES Test Attachments

Artifacts

Error message Assert.Equal() Failure: Strings differ ↓ (pos 0) Expected: "7" Actual: ""

Stack trace at Microsoft.Extensions.Caching.Hybrid.Tests.LogCollector.AssertErrors(Int32[] errorIds) in /mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LogCollector.cs:line 60 at Microsoft.Extensions.Caching.Hybrid.Tests.UnreliableL2Tests.WriteFailureInvisible(BreakType writeBreak, Int32[] errorIds) in /mnt/vss/_work/1/s/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/UnreliableL2Tests.cs:line 49 --- End of stack trace from previous location ---


💡 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

Copilot avatar Nov 21 '25 15:11 Copilot