You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.3 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

namespace Polly8Study.Test
{
/// <summary>
/// Polly8超时策略 测试
/// 关键:
/// CancellationToken没有这个是不起使用的
/// 就是之前版本中的乐观超时,悲观超时貌似取消了
/// </summary>
public class Polly8RetryStrategyTest
{
private readonly ITestOutputHelper _output;
public Polly8RetryStrategyTest(ITestOutputHelper testOutput)
{
_output = testOutput;
}
/// <summary>
/// 重试策略
/// </summary>
[Fact]
public void Test()
{
ResiliencePipeline pipeline = new ResiliencePipelineBuilder()
.AddRetry(new RetryStrategyOptions
{
ShouldHandle = new Polly.PredicateBuilder().Handle<Exception>(),
Delay = TimeSpan.FromSeconds(1),
MaxRetryAttempts = 3,
BackoffType = DelayBackoffType.Constant
})
.Build(); // After all necessary strategies are added, call Build() to create the pipeline.
// Synchronous execution
pipeline.Execute(static () =>
{
// Your code goes here
});
}
}
}