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

Use Polly instead of AnyRetry #3

Merged
merged 2 commits into from
Mar 18, 2024
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 visual-dotnet/SauceLabs.Visual/SauceLabs.Visual.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AnyRetry" Version="1.0.31" />
<PackageReference Include="Polly" Version="8.3.1" />
<PackageReference Include="GraphQL.Client" Version="6.0.2" />
<PackageReference Include="GraphQL.Client.Abstractions" Version="6.0.2" />
<PackageReference Include="GraphQL.Client.Serializer.Newtonsoft" Version="6.0.2" />
Expand Down
36 changes: 14 additions & 22 deletions visual-dotnet/SauceLabs.Visual/VisualClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AnyRetry;
using AnyRetry.Math;
using OpenQA.Selenium;
using Polly;
using Polly.Retry;
using SauceLabs.Visual.GraphQL;
using SauceLabs.Visual.Models;
using SauceLabs.Visual.Utils;
Expand All @@ -24,6 +24,7 @@ public class VisualClient : IDisposable
public VisualBuild Build { get; }
private readonly bool _externalBuild;
public bool CaptureDom { get; set; } = false;
private ResiliencePipeline _retryPipeline;

/// <summary>
/// Creates a new instance of <c>VisualClient</c>
Expand Down Expand Up @@ -56,6 +57,16 @@ public VisualClient(WebDriver wd, Region region, string username, string accessK
var createBuildResponse = CreateBuild(buildOptions).Result;
Build = new VisualBuild(createBuildResponse.Id, createBuildResponse.Url);
_externalBuild = false;

_retryPipeline = new ResiliencePipelineBuilder()
.AddRetry(new RetryStrategyOptions()
{
Name = "VisualRetryPolicy",
Delay = TimeSpan.FromSeconds(1),
MaxRetryAttempts = 10
})
.AddTimeout(TimeSpan.FromSeconds(15))
Comment on lines +65 to +68
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it uses different values from the ones before. Why 1 / 10 / 15?

.Build();
}

/// <summary>
Expand Down Expand Up @@ -133,26 +144,7 @@ public void Dispose()
/// <exception cref="VisualClientException"></exception>
public async Task<Dictionary<DiffStatus, int>> VisualResults()
{
var policyOptions = new RetryPolicyOptions
{
EasingFunction = EasingFunction.ExponentialEaseOut,
MaxRetryInterval = TimeSpan.FromSeconds(5),
MaxRetrySteps = 10
};
var result = await Retry.Do(async () => await FetchVisualResults(Build.Id),
retryInterval: TimeSpan.FromMilliseconds(100),
retryLimit: 10,
retryPolicy: RetryPolicy.ExponentialBackoff,
retryPolicyOptions: policyOptions,
onFailure: null,
mustReturnTrueBeforeFail: null,
exceptionTypes: typeof(VisualClientException)
);
if (result == null)
{
throw new VisualClientException("diff results were not available in time");
}
return result;
return await _retryPipeline.ExecuteAsync(async token => await FetchVisualResults(Build.Id));
}

private async Task<Dictionary<DiffStatus, int>> FetchVisualResults(string buildId)
Expand Down
Loading