-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
bb08832
commit a3ca9d0
Showing
16 changed files
with
127 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
#nullable enable | ||
Polly.ResiliencePipelineBuilderBase.ContextPool.get -> Polly.ResilienceContextPool? | ||
Polly.ResiliencePipelineBuilderBase.ContextPool.set -> void |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
test/Polly.Extensions.Tests/Issues/IssuesTests.DynamicContextPool_1687.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Polly.Registry; | ||
|
||
namespace Polly.Extensions.Tests.Issues; | ||
|
||
public partial class IssuesTests | ||
{ | ||
private class CustomResilienceContextPool : ResilienceContextPool | ||
{ | ||
public override ResilienceContext Get(ResilienceContextCreationArguments arguments) | ||
{ | ||
if (arguments.ContinueOnCapturedContext is null) | ||
{ | ||
arguments = new ResilienceContextCreationArguments(arguments.OperationKey, continueOnCapturedContext: true, arguments.CancellationToken); | ||
} | ||
|
||
return Shared.Get(arguments); | ||
} | ||
|
||
public override void Return(ResilienceContext context) => Shared.Return(context); | ||
} | ||
|
||
private class ContextCreationTestStrategy : ResilienceStrategy | ||
{ | ||
public int HitCount { get; private set; } | ||
|
||
protected override async ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback, | ||
ResilienceContext context, | ||
TState state) | ||
{ | ||
context.ContinueOnCapturedContext.Should().BeTrue(); | ||
|
||
HitCount++; | ||
|
||
return await callback(context, state); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task DynamicContextPool_1687() | ||
{ | ||
var pool = new CustomResilienceContextPool(); | ||
var strategy = new ContextCreationTestStrategy(); | ||
var services = new ServiceCollection(); | ||
string key = "my-key"; | ||
|
||
services.AddResiliencePipelineRegistry<string>(options => options.BuilderFactory = () => new ResiliencePipelineBuilder | ||
{ | ||
ContextPool = pool, | ||
}); | ||
|
||
services.AddResiliencePipeline(key, builder => | ||
{ | ||
builder.ContextPool.Should().Be(pool); | ||
builder.AddStrategy(strategy); | ||
}); | ||
|
||
// create the pipeline provider | ||
var provider = services.BuildServiceProvider().GetRequiredService<ResiliencePipelineProvider<string>>(); | ||
|
||
var pipeline = provider.GetPipeline(key); | ||
|
||
await pipeline.ExecuteAsync(async ct => await default(ValueTask)); | ||
|
||
strategy.HitCount.Should().BeGreaterThan(0); | ||
} | ||
} |