Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unstable test #1396

Merged
merged 4 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Polly.Core/Retry/RetryResilienceStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ protected override async ValueTask<Outcome<T>> ExecuteCallbackAsync<TState>(Func
await DisposeHelper.TryDisposeSafeAsync(resultValue, context.IsSynchronous).ConfigureAwait(context.ContinueOnCapturedContext);
}

// stryker disable once equality : no means to test this
// stryker disable once boolean : no means to test this
// stryker disable once all : no means to test this
if (delay > TimeSpan.Zero)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,12 @@ public async Task ExecuteAsync_EnsurePrimaryTaskCancelled_Ok()

// assert
_timeProvider.Advance(TimeSpan.FromHours(2));
cancelled.WaitOne(TimeSpan.FromSeconds(1)).Should().BeTrue();

await TestUtilities.AssertWithTimeoutAsync(() =>
{
cancelled.WaitOne(TimeSpan.FromMilliseconds(10)).Should().BeTrue();
});

await task;
}

Expand Down
19 changes: 6 additions & 13 deletions test/Polly.Core.Tests/Retry/RetryResilienceStrategyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,20 @@ public void Retry_Infinite_Respected()
}

[Fact]
public async Task RetryDelayGenerator_Respected()
public void RetryDelayGenerator_Respected()
{
int retries = 0;
int generatedValues = 0;

var retries = 0;
var generatedValues = 0;
var delay = TimeSpan.FromMilliseconds(120);
var provider = TimeProvider.System;

_options.ShouldHandle = _ => PredicateResult.True;
_options.RetryCount = 3;
_options.BackoffType = RetryBackoffType.Constant;

_options.OnRetry = _ =>
_options.OnRetry = args =>
{
retries++;
args.Arguments.RetryDelay.Should().Be(delay);
return default;
};
_options.RetryDelayGenerator = _ =>
Expand All @@ -180,16 +179,10 @@ public async Task RetryDelayGenerator_Respected()
return new ValueTask<TimeSpan>(delay);
};

var before = provider.GetUtcNow();

var sut = CreateSut(provider);
await sut.ExecuteAsync(_ => default);
CreateSut(TimeProvider.System).Execute(_ => { });

retries.Should().Be(3);
generatedValues.Should().Be(3);

var after = provider.GetUtcNow();
(after - before).Should().BeGreaterThanOrEqualTo(delay.Add(delay).Add(delay));
}

[Fact]
Expand Down