Skip to content

Commit

Permalink
Fix a thread local test
Browse files Browse the repository at this point in the history
- Updated conditional fact to require precise GC for the test
- Fixes dotnet#57102
  • Loading branch information
kouvel committed Oct 26, 2021
1 parent 9556913 commit 17c249a
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/libraries/System.Threading/tests/ThreadLocalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static void RunThreadLocalTest4_Value_NegativeCases()
});
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[ConditionalFact(nameof(IsThreadingAndPreciseGcSupported))]
public static void RunThreadLocalTest5_Dispose()
{
// test recycling the combination index;
Expand All @@ -128,15 +128,15 @@ public static void RunThreadLocalTest5_Dispose()
// it to be run on another thread.
new Task(() => { threadLocal.Value = new SetMreOnFinalize(mres); }, TaskCreationOptions.LongRunning).Start(TaskScheduler.Default);

SpinWait.SpinUntil(() =>
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
return mres.IsSet;
}, ThreadTestHelpers.UnexpectedTimeoutMilliseconds);

Assert.True(mres.IsSet);
ThreadTestHelpers.WaitForConditionWithCustomDelay(
() => mres.IsSet,
() =>
{
Thread.Sleep(1);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
});
}

[Fact]
Expand Down Expand Up @@ -478,5 +478,8 @@ public SetMreOnFinalize(ManualResetEventSlim mres)
_mres.Set();
}
}

public static bool IsThreadingAndPreciseGcSupported =>
PlatformDetection.IsThreadingSupported && PlatformDetection.IsPreciseGcSupported;
}
}

0 comments on commit 17c249a

Please sign in to comment.