Skip to content

Commit edc976e

Browse files
lewingCopilot
andcommitted
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>
1 parent 0d0e129 commit edc976e

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/libraries/System.Resources.Extensions/tests/BinaryResourceWriterUnitTest.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ public static void EmbeddedResourcesAreUpToDate()
517517
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBinaryFormatterSupported))]
518518
[InlineData(false)]
519519
[InlineData(true)]
520-
public static void TestResourceManagerIsSafeForConcurrentAccessAndEnumeration(bool useEnumeratorEntry)
520+
public static async Task TestResourceManagerIsSafeForConcurrentAccessAndEnumeration(bool useEnumeratorEntry)
521521
{
522522
ResourceManager manager = new(
523523
typeof(TestData).FullName,
@@ -534,7 +534,10 @@ public static void TestResourceManagerIsSafeForConcurrentAccessAndEnumeration(bo
534534
TaskScheduler.Default))
535535
.ToArray();
536536

537-
Assert.True(Task.WaitAll(tasks, TimeSpan.FromSeconds(30)));
537+
Task allTasks = Task.WhenAll(tasks);
538+
Task completed = await Task.WhenAny(allTasks, Task.Delay(TimeSpan.FromSeconds(120)));
539+
Assert.True(completed == allTasks, "Timed out waiting for concurrent enumeration tasks");
540+
await allTasks; // propagates any real exceptions
538541

539542
void WaitForBarrierThenEnumerateResources()
540543
{

0 commit comments

Comments
 (0)