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 tests #1115

Merged
merged 3 commits into from
Apr 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
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var configuration = Argument<string>("configuration", "Release");
//////////////////////////////////////////////////////////////////////

#Tool "xunit.runner.console&version=2.4.2"
#Tool "dotnet-stryker&version=3.7.0"
#Tool "dotnet-stryker&version=3.7.1"

//////////////////////////////////////////////////////////////////////
// EXTERNAL NUGET LIBRARIES
Expand Down
4 changes: 0 additions & 4 deletions src/Polly.Core.Tests/ResilienceStrategyTests.Async.Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ private static IEnumerable<ExecuteParameters> ExecuteAsTaskAsync_EnsureCorrectBe
{
Caption = "ExecuteAsTaskAsync_NoCancellation",
AssertContext = AssertResilienceContext,
AssertContextAfter = AssertContextNotInitialized,
};

yield return new ExecuteParameters(r => r.ExecuteTaskAsync(async t => { t.Should().Be(CancellationToken); }, CancellationToken))
{
Caption = "ExecuteAsTaskAsync_Cancellation",
AssertContext = AssertResilienceContextAndToken,
AssertContextAfter = AssertContextNotInitialized,
};

yield return new ExecuteParameters(r => r.ExecuteTaskAsync(async (_, s) => { s.Should().Be("dummy-state"); }, ResilienceContext.Get(), "dummy-state"))
Expand All @@ -45,8 +43,6 @@ static void AssertResilienceContextAndToken(ResilienceContext context)
context.CancellationToken.Should().Be(CancellationToken);
}

static void AssertContextNotInitialized(ResilienceContext context) => context.IsInitialized.Should().BeFalse();

static void AssertContextInitialized(ResilienceContext context) => context.IsInitialized.Should().BeTrue();
}

Expand Down
4 changes: 0 additions & 4 deletions src/Polly.Core.Tests/ResilienceStrategyTests.Async.TaskT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ private static IEnumerable<ExecuteParameters> ExecuteAsTaskAsyncT_EnsureCorrectB
{
Caption = "ExecuteAsTaskAsyncT_NoCancellation",
AssertContext = AssertResilienceContext,
AssertContextAfter = AssertContextNotInitialized,
};

yield return new ExecuteParameters<long>(r => r.ExecuteTaskAsync(async t => { t.Should().Be(CancellationToken); return result; }, CancellationToken), result)
{
Caption = "ExecuteAsTaskAsyncT_Cancellation",
AssertContext = AssertResilienceContextAndToken,
AssertContextAfter = AssertContextNotInitialized,
};

yield return new ExecuteParameters<long>(r => r.ExecuteTaskAsync(async (_, s) => { s.Should().Be("dummy-state"); return result; }, ResilienceContext.Get(), "dummy-state"), result)
Expand All @@ -48,8 +46,6 @@ static void AssertResilienceContextAndToken(ResilienceContext context)
context.CancellationToken.Should().Be(CancellationToken);
}

static void AssertContextNotInitialized(ResilienceContext context) => context.IsInitialized.Should().BeFalse();

static void AssertContextInitialized(ResilienceContext context) => context.IsInitialized.Should().BeTrue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ private static IEnumerable<ExecuteParameters> ExecuteAsync_EnsureCorrectBehavior
{
Caption = "ExecuteAsync_NoCancellation",
AssertContext = AssertResilienceContext,
AssertContextAfter = AssertContextNotInitialized,
};

yield return new ExecuteParameters(r => r.ExecuteValueTaskAsync(async t => { t.Should().Be(CancellationToken); }, CancellationToken))
{
Caption = "ExecuteAsync_Cancellation",
AssertContext = AssertResilienceContextAndToken,
AssertContextAfter = AssertContextNotInitialized,
};

yield return new ExecuteParameters(r => r.ExecuteValueTaskAsync(async (_, s) => { s.Should().Be("dummy-state"); }, ResilienceContext.Get(), "dummy-state"))
Expand All @@ -45,8 +43,6 @@ static void AssertResilienceContextAndToken(ResilienceContext context)
context.CancellationToken.Should().Be(CancellationToken);
}

static void AssertContextNotInitialized(ResilienceContext context) => context.IsInitialized.Should().BeFalse();

static void AssertContextInitialized(ResilienceContext context) => context.IsInitialized.Should().BeTrue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ private static IEnumerable<ExecuteParameters> ExecuteAsyncT_EnsureCorrectBehavio
{
Caption = "ExecuteAsyncT_NoCancellation",
AssertContext = AssertResilienceContext,
AssertContextAfter = AssertContextNotInitialized,
};

yield return new ExecuteParameters<long>(r => r.ExecuteValueTaskAsync(async t => { t.Should().Be(CancellationToken); return result; }, CancellationToken), result)
{
Caption = "ExecuteAsyncT_Cancellation",
AssertContext = AssertResilienceContextAndToken,
AssertContextAfter = AssertContextNotInitialized,
};

yield return new ExecuteParameters<long>(r => r.ExecuteValueTaskAsync(async (_, s) => { s.Should().Be("dummy-state"); return result; }, ResilienceContext.Get(), "dummy-state"), result)
Expand All @@ -48,8 +46,6 @@ static void AssertResilienceContextAndToken(ResilienceContext context)
context.CancellationToken.Should().Be(CancellationToken);
}

static void AssertContextNotInitialized(ResilienceContext context) => context.IsInitialized.Should().BeFalse();

static void AssertContextInitialized(ResilienceContext context) => context.IsInitialized.Should().BeTrue();
}

Expand Down
4 changes: 0 additions & 4 deletions src/Polly.Core.Tests/ResilienceStrategyTests.Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ private static IEnumerable<ExecuteParameters> Execute_EnsureCorrectBehavior_Exec
{
Caption = "Execute_NoCancellation",
AssertContext = AssertResilienceContext,
AssertContextAfter = AssertContextNotInitialized,
};

yield return new ExecuteParameters(r => r.Execute(t => { t.Should().Be(CancellationToken); }, CancellationToken))
{
Caption = "Execute_Cancellation",
AssertContext = AssertResilienceContextAndToken,
AssertContextAfter = AssertContextNotInitialized,
};

yield return new ExecuteParameters(r => r.Execute((_, s) => { s.Should().Be("dummy-state"); }, ResilienceContext.Get(), "dummy-state"))
Expand All @@ -43,8 +41,6 @@ static void AssertResilienceContextAndToken(ResilienceContext context)
context.CancellationToken.Should().Be(CancellationToken);
}

static void AssertContextNotInitialized(ResilienceContext context) => context.IsInitialized.Should().BeFalse();

static void AssertContextInitialized(ResilienceContext context) => context.IsInitialized.Should().BeTrue();
}

Expand Down
4 changes: 0 additions & 4 deletions src/Polly.Core.Tests/ResilienceStrategyTests.SyncT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ private static IEnumerable<ExecuteParameters> ExecuteT_EnsureCorrectBehavior_Exe
{
Caption = "ExecuteT_NoCancellation",
AssertContext = AssertResilienceContext,
AssertContextAfter = AssertContextNotInitialized,
};

yield return new ExecuteParameters<long>(r => r.Execute(t => { t.Should().Be(CancellationToken); return result; }, CancellationToken), result)
{
Caption = "ExecuteT_Cancellation",
AssertContext = AssertResilienceContextAndToken,
AssertContextAfter = AssertContextNotInitialized,
};

yield return new ExecuteParameters<long>(r => r.Execute((_, s) => { s.Should().Be("dummy-state"); return result; }, ResilienceContext.Get(), "dummy-state"), result)
Expand All @@ -46,8 +44,6 @@ static void AssertResilienceContextAndToken(ResilienceContext context)
context.CancellationToken.Should().Be(CancellationToken);
}

static void AssertContextNotInitialized(ResilienceContext context) => context.IsInitialized.Should().BeFalse();

static void AssertContextInitialized(ResilienceContext context) => context.IsInitialized.Should().BeTrue();
}

Expand Down
18 changes: 18 additions & 0 deletions src/Polly.Core.Tests/Utils/TimeProviderExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ await TestUtils.AssertWithTimeoutAsync(async () =>
});
}

[Fact]
public async Task DelayAsync_SystemSynchronousWhenCancelled_Ok()
{
using var cts = new CancellationTokenSource(5);
var delay = TimeSpan.FromMilliseconds(10);
var context = ResilienceContext.Get();
context.Initialize<VoidResult>(isSynchronous: true);
context.CancellationToken = cts.Token;

await TestUtils.AssertWithTimeoutAsync(async () =>
{
await TimeProvider.System
.Invoking(p => p.DelayAsync(delay, context))
.Should()
.ThrowAsync<OperationCanceledException>();
});
}

[InlineData(false, false)]
[InlineData(false, true)]
[InlineData(true, false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class RateLimiterResilienceStrategyBuilderExtensionsTests
};

[MemberData(nameof(Data))]
[Theory]
[Theory(Skip = "https://github.com/stryker-mutator/stryker-net/issues/2144")]
public void AddRateLimiter_Extensions_Ok(Action<ResilienceStrategyBuilder> configure)
{
var builder = new ResilienceStrategyBuilder();
Expand All @@ -66,6 +66,19 @@ public void AddRateLimiter_Extensions_Ok(Action<ResilienceStrategyBuilder> confi
builder.Build().Should().BeOfType<RateLimiterResilienceStrategy>();
}

[Fact]
public void AddRateLimiter_AllExtensions_Ok()
{
foreach (var configure in Data.Select(v => v[0]).Cast<Action<ResilienceStrategyBuilder>>())
{
var builder = new ResilienceStrategyBuilder();

configure(builder);

builder.Build().Should().BeOfType<RateLimiterResilienceStrategy>();
}
}

[Fact]
public void AddRateLimiter_InvalidOptions_Throws()
{
Expand Down