From 9f004a2d18222c9d31756d380b5f387d11d4c135 Mon Sep 17 00:00:00 2001 From: gabidabet <42586945+gabidabet@users.noreply.github.com> Date: Sat, 28 Sep 2024 07:41:41 +0100 Subject: [PATCH] Fix #2288 (#2313) Remove xunit workaround. --- .../Hedging/HedgingStrategyOptionsTests.cs | 10 ++++++++-- test/Polly.Core.Tests/Polly.Core.Tests.csproj | 5 ----- test/Polly.Core.Tests/xunit.runner.json | 4 ---- 3 files changed, 8 insertions(+), 11 deletions(-) delete mode 100644 test/Polly.Core.Tests/xunit.runner.json diff --git a/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs b/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs index 51d02dcd240..cf833edc2aa 100644 --- a/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs +++ b/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs @@ -27,6 +27,7 @@ public async Task HedgingActionGenerator_EnsureDefaults(bool synchronous) var options = new HedgingStrategyOptions(); var context = ResilienceContextPool.Shared.Get().Initialize(synchronous); var threadId = Thread.CurrentThread.ManagedThreadId; + using var semaphore = new SemaphoreSlim(0); var action = options.ActionGenerator(new HedgingActionGeneratorArguments(context, context, 1, c => { @@ -39,11 +40,16 @@ public async Task HedgingActionGenerator_EnsureDefaults(bool synchronous) Thread.CurrentThread.ManagedThreadId.Should().Be(threadId); } + semaphore.Release(); return Outcome.FromResultAsValueTask(99); }))!; - action.Should().NotBeNull(); - (await action()).Result.Should().Be(99); + var task = action(); + semaphore + .Wait(TimeSpan.FromSeconds(20)) + .Should() + .BeTrue("The test thread failed to complete within the timeout"); + (await task).Result.Should().Be(99); } [Fact] diff --git a/test/Polly.Core.Tests/Polly.Core.Tests.csproj b/test/Polly.Core.Tests/Polly.Core.Tests.csproj index 898e2cdf830..33b7e17deba 100644 --- a/test/Polly.Core.Tests/Polly.Core.Tests.csproj +++ b/test/Polly.Core.Tests/Polly.Core.Tests.csproj @@ -26,9 +26,4 @@ - - - - - diff --git a/test/Polly.Core.Tests/xunit.runner.json b/test/Polly.Core.Tests/xunit.runner.json deleted file mode 100644 index 8e343ae0a7f..00000000000 --- a/test/Polly.Core.Tests/xunit.runner.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", - "parallelAlgorithm": "aggressive" -}