From e6e22d08b57d3f1fbee4dd5bf695f28262365e4e Mon Sep 17 00:00:00 2001 From: wanggaofeng <15601716045@163.com> Date: Thu, 1 Aug 2024 21:07:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Polly8Study.Test/Polly8RetryStrategyTest.cs | 42 +++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Polly8Study.Test/Polly8RetryStrategyTest.cs diff --git a/Polly8Study.Test/Polly8RetryStrategyTest.cs b/Polly8Study.Test/Polly8RetryStrategyTest.cs new file mode 100644 index 0000000..bfeb32a --- /dev/null +++ b/Polly8Study.Test/Polly8RetryStrategyTest.cs @@ -0,0 +1,42 @@ +namespace Polly8Study.Test +{ + /// + /// Polly8超时策略 测试 + /// 关键: + /// CancellationToken,没有这个是不起使用的 + /// 就是之前版本中的乐观超时,悲观超时貌似取消了 + /// + public class Polly8RetryStrategyTest + { + private readonly ITestOutputHelper _output; + + public Polly8RetryStrategyTest(ITestOutputHelper testOutput) + { + _output = testOutput; + } + + /// + /// 重试策略 + /// + [Fact] + public void Test() + { + ResiliencePipeline pipeline = new ResiliencePipelineBuilder() + .AddRetry(new RetryStrategyOptions + { + ShouldHandle = new Polly.PredicateBuilder().Handle(), + 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 + }); + } + + } +} \ No newline at end of file