From 3941d7dddd27e0d5de14553bde7b159f292a0966 Mon Sep 17 00:00:00 2001 From: gabidabet Date: Fri, 27 Sep 2024 00:45:27 +0100 Subject: [PATCH 1/4] revert Workaround --- test/Polly.Core.Tests/Polly.Core.Tests.csproj | 5 ----- test/Polly.Core.Tests/xunit.runner.json | 4 ---- 2 files changed, 9 deletions(-) delete mode 100644 test/Polly.Core.Tests/xunit.runner.json 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" -} From 110e44ed533a796e177cc86128a9fd84e41f3957 Mon Sep 17 00:00:00 2001 From: gabidabet Date: Fri, 27 Sep 2024 00:45:47 +0100 Subject: [PATCH 2/4] fix the test by letting only one task runs at the time --- .../Hedging/HedgingStrategyOptionsTests.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs b/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs index 51d02dcd240..5464f8484e3 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,13 @@ 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(); + (await task).Result.Should().Be(99); } [Fact] From 29011392bd81741f9f09bbe77c16898b592fdb3c Mon Sep 17 00:00:00 2001 From: gabidabet Date: Sat, 28 Sep 2024 00:24:44 +0100 Subject: [PATCH 3/4] apply review --- test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs b/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs index 5464f8484e3..c2b07d9939b 100644 --- a/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs +++ b/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs @@ -45,7 +45,10 @@ public async Task HedgingActionGenerator_EnsureDefaults(bool synchronous) }))!; var task = action(); - semaphore.Wait(); + semaphore + .Wait(TimeSpan.FromSeconds(20)) + .Should() + .BeTrue($"The test thread failed to enter the {nameof(semaphore)}, the hedging callback didn't executed"); (await task).Result.Should().Be(99); } From df6a367329fa90303b9c4b91e40007e2d50cba1c Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Sat, 28 Sep 2024 07:09:55 +0100 Subject: [PATCH 4/4] Update assertion message --- test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs b/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs index c2b07d9939b..cf833edc2aa 100644 --- a/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs +++ b/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs @@ -48,7 +48,7 @@ public async Task HedgingActionGenerator_EnsureDefaults(bool synchronous) semaphore .Wait(TimeSpan.FromSeconds(20)) .Should() - .BeTrue($"The test thread failed to enter the {nameof(semaphore)}, the hedging callback didn't executed"); + .BeTrue("The test thread failed to complete within the timeout"); (await task).Result.Should().Be(99); }