From d6d9c6012c42f38906f72e07e7dd57cfc49da7a1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 21 Nov 2025 15:09:19 +0000 Subject: [PATCH 1/3] Initial plan From c07795c54436a418ee00ab4b4645aa9f3e8b0276 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 21 Nov 2025 15:26:38 +0000 Subject: [PATCH 2/3] Fix flaky UnreliableL2Tests.WriteFailureInvisible test by waiting for logs Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --- .../LogCollector.cs | 33 +++++++++++++++++++ .../UnreliableL2Tests.cs | 4 ++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LogCollector.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LogCollector.cs index bdb5ff981c0..1b350135ee7 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LogCollector.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LogCollector.cs @@ -31,6 +31,39 @@ public void WriteTo(ITestOutputHelper log) } } + public async Task WaitForLogsAsync(int[] expectedErrorIds, TimeSpan timeout) + { + var deadline = DateTime.UtcNow + timeout; + while (DateTime.UtcNow < deadline) + { + lock (_items) + { + if (_items.Count >= expectedErrorIds.Length) + { + // Check if we have the expected logs + bool match = true; + for (int i = 0; i < expectedErrorIds.Length; i++) + { + if (_items[i].eventId.Id != expectedErrorIds[i]) + { + match = false; + break; + } + } + + if (match) + { + return; // Success + } + } + } + + await Task.Delay(10); + } + + // Timeout reached, will fail in AssertErrors + } + public void AssertErrors(int[] errorIds) { lock (_items) diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/UnreliableL2Tests.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/UnreliableL2Tests.cs index f6232357651..bba5020f58b 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/UnreliableL2Tests.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/UnreliableL2Tests.cs @@ -43,7 +43,9 @@ public async Task WriteFailureInvisible(BreakType writeBreak, params int[] error } await l2.LastWrite; // allows out-of-band write to complete - await Task.Delay(150); // even then: thread jitter can cause problems + + // Wait for logs to be written (with timeout to avoid hanging on failure) + await log.WaitForLogsAsync(errorIds, TimeSpan.FromSeconds(5)); log.WriteTo(testLog); log.AssertErrors(errorIds); From bf465a74e57282bbfb3850f4d418e06c6d4af0b7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 21 Nov 2025 15:30:59 +0000 Subject: [PATCH 3/3] Improve WaitForLogsAsync to match AssertErrors exact matching logic Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> --- .../LogCollector.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LogCollector.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LogCollector.cs index 1b350135ee7..553fe1f1cd4 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LogCollector.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LogCollector.cs @@ -38,9 +38,9 @@ public async Task WaitForLogsAsync(int[] expectedErrorIds, TimeSpan timeout) { lock (_items) { - if (_items.Count >= expectedErrorIds.Length) + // Check for exact match to avoid race conditions with AssertErrors + if (_items.Count == expectedErrorIds.Length) { - // Check if we have the expected logs bool match = true; for (int i = 0; i < expectedErrorIds.Length; i++) { @@ -56,6 +56,13 @@ public async Task WaitForLogsAsync(int[] expectedErrorIds, TimeSpan timeout) return; // Success } } + + // If we have more logs than expected, something unexpected happened + // Stop waiting to let AssertErrors report the mismatch + if (_items.Count > expectedErrorIds.Length) + { + return; + } } await Task.Delay(10);