From edc976e21d5daf1f3ebbd417a509869f241b4abe Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Sat, 14 Mar 2026 21:17:10 -0500 Subject: [PATCH] Fix flaky TestResourceManagerIsSafeForConcurrentAccessAndEnumeration timeout The test uses Task.WaitAll with a 30-second timeout to wait for 10 threads concurrently enumerating resources. On loaded CI agents, 30s is not always enough, causing Assert.True(false) with no useful diagnostic. Switch to await Task.WhenAll().WaitAsync(120s): - WhenAll propagates actual thread-safety exceptions instead of swallowing them behind Assert.True(false) - 120s gives 4x more headroom for slow CI agents while still providing a timeout safety net This test has been filed as a Known Build Error three times (#80277, #86013, #125448) across 3+ years. Fixes #125448 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../tests/BinaryResourceWriterUnitTest.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Resources.Extensions/tests/BinaryResourceWriterUnitTest.cs b/src/libraries/System.Resources.Extensions/tests/BinaryResourceWriterUnitTest.cs index 6764f154b9f7b4..c801e230582a99 100644 --- a/src/libraries/System.Resources.Extensions/tests/BinaryResourceWriterUnitTest.cs +++ b/src/libraries/System.Resources.Extensions/tests/BinaryResourceWriterUnitTest.cs @@ -517,7 +517,7 @@ public static void EmbeddedResourcesAreUpToDate() [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBinaryFormatterSupported))] [InlineData(false)] [InlineData(true)] - public static void TestResourceManagerIsSafeForConcurrentAccessAndEnumeration(bool useEnumeratorEntry) + public static async Task TestResourceManagerIsSafeForConcurrentAccessAndEnumeration(bool useEnumeratorEntry) { ResourceManager manager = new( typeof(TestData).FullName, @@ -534,7 +534,10 @@ public static void TestResourceManagerIsSafeForConcurrentAccessAndEnumeration(bo TaskScheduler.Default)) .ToArray(); - Assert.True(Task.WaitAll(tasks, TimeSpan.FromSeconds(30))); + Task allTasks = Task.WhenAll(tasks); + Task completed = await Task.WhenAny(allTasks, Task.Delay(TimeSpan.FromSeconds(120))); + Assert.True(completed == allTasks, "Timed out waiting for concurrent enumeration tasks"); + await allTasks; // propagates any real exceptions void WaitForBarrierThenEnumerateResources() {