2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
4
using System . Threading . Tasks ;
5
- using AnyRetry ;
6
- using AnyRetry . Math ;
7
5
using OpenQA . Selenium ;
6
+ using Polly ;
7
+ using Polly . Retry ;
8
8
using SauceLabs . Visual . GraphQL ;
9
9
using SauceLabs . Visual . Models ;
10
10
using SauceLabs . Visual . Utils ;
@@ -24,6 +24,7 @@ public class VisualClient : IDisposable
24
24
public VisualBuild Build { get ; }
25
25
private readonly bool _externalBuild ;
26
26
public bool CaptureDom { get ; set ; } = false ;
27
+ private ResiliencePipeline _retryPipeline ;
27
28
28
29
/// <summary>
29
30
/// Creates a new instance of <c>VisualClient</c>
@@ -56,6 +57,16 @@ public VisualClient(WebDriver wd, Region region, string username, string accessK
56
57
var createBuildResponse = CreateBuild ( buildOptions ) . Result ;
57
58
Build = new VisualBuild ( createBuildResponse . Id , createBuildResponse . Url ) ;
58
59
_externalBuild = false ;
60
+
61
+ _retryPipeline = new ResiliencePipelineBuilder ( )
62
+ . AddRetry ( new RetryStrategyOptions ( )
63
+ {
64
+ Name = "VisualRetryPolicy" ,
65
+ Delay = TimeSpan . FromSeconds ( 1 ) ,
66
+ MaxRetryAttempts = 10
67
+ } )
68
+ . AddTimeout ( TimeSpan . FromSeconds ( 15 ) )
69
+ . Build ( ) ;
59
70
}
60
71
61
72
/// <summary>
@@ -133,26 +144,7 @@ public void Dispose()
133
144
/// <exception cref="VisualClientException"></exception>
134
145
public async Task < Dictionary < DiffStatus , int > > VisualResults ( )
135
146
{
136
- var policyOptions = new RetryPolicyOptions
137
- {
138
- EasingFunction = EasingFunction . ExponentialEaseOut ,
139
- MaxRetryInterval = TimeSpan . FromSeconds ( 5 ) ,
140
- MaxRetrySteps = 10
141
- } ;
142
- var result = await Retry . Do ( async ( ) => await FetchVisualResults ( Build . Id ) ,
143
- retryInterval : TimeSpan . FromMilliseconds ( 100 ) ,
144
- retryLimit : 10 ,
145
- retryPolicy : RetryPolicy . ExponentialBackoff ,
146
- retryPolicyOptions : policyOptions ,
147
- onFailure : null ,
148
- mustReturnTrueBeforeFail : null ,
149
- exceptionTypes : typeof ( VisualClientException )
150
- ) ;
151
- if ( result == null )
152
- {
153
- throw new VisualClientException ( "diff results were not available in time" ) ;
154
- }
155
- return result ;
147
+ return await _retryPipeline . ExecuteAsync ( async token => await FetchVisualResults ( Build . Id ) ) ;
156
148
}
157
149
158
150
private async Task < Dictionary < DiffStatus , int > > FetchVisualResults ( string buildId )
0 commit comments