Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Komissarov committed Mar 26, 2024
1 parent 9067c57 commit 6e5ae71
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Tms.Adapter/Tms.Adapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<ItemGroup>
<PackageReference Include="Fody" Version="6.6.4" />
<PackageReference Include="MethodBoundaryAspect.Fody" Version="2.0.148" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="17.5.0" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="17.9.0" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
</ItemGroup>

Expand Down
20 changes: 12 additions & 8 deletions TmsRunner/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using CommandLine;
using Microsoft.Extensions.DependencyInjection;
using Polly;
using Polly.Extensions.Http;
using Polly.Retry;
using System.Net;
using TestIT.ApiClient.Api;
using TestIT.ApiClient.Client;
using Tms.Adapter.Utils;
using TmsRunner.Client;
using TmsRunner.Extensions;
Expand All @@ -21,7 +22,7 @@ internal class Program
{
public static async Task<int> Main(string[] args)
{
var services = BuildServices(args);
using var services = BuildServices(args);
var log = LoggerFactory.GetLogger(services.GetRequiredService<AdapterConfig>().IsDebug).ForContext<Program>();

log.Information("Adapter works in {Mode} mode", services.GetRequiredService<TmsSettings>().AdapterMode);
Expand Down Expand Up @@ -111,10 +112,10 @@ private static ServiceProvider BuildServices(string[] args)
_ = serviceCollection.AddHttpClient(nameof(HttpClientNames.Default), client =>
{
client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher;
client.DefaultRequestVersion = HttpVersion.Version10;
client.DefaultRequestVersion = HttpVersion.Version11;
})
.SetHandlerLifetime(TimeSpan.FromMinutes(20))
.AddPolicyHandler(RetryPolicy);
.AddPolicyHandler(GetRetryPolicy());

_ = serviceCollection
.AddSingleton(GetAdapterConfiguration(args))
Expand Down Expand Up @@ -162,8 +163,11 @@ private static ServiceProvider BuildServices(string[] args)
return serviceCollection.BuildServiceProvider();
}

private static IAsyncPolicy<HttpResponseMessage> RetryPolicy => Policy<HttpResponseMessage>
.Handle<Exception>(exception => exception.GetType() != typeof(ApiException))
.OrResult(response => !response.IsSuccessStatusCode)
.WaitAndRetryAsync(4, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
private static AsyncRetryPolicy<HttpResponseMessage> GetRetryPolicy()
{
return HttpPolicyExtensions
.HandleTransientHttpError()
.OrResult(response => !response.IsSuccessStatusCode)
.WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
}
}
8 changes: 0 additions & 8 deletions TmsRunner/TmsRunner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.3" />
<PackageReference Include="Microsoft.TestPlatform" Version="17.9.0" />
Expand All @@ -33,14 +29,10 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MSTest.TestFramework" Version="3.2.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
<PackageReference Include="System.Runtime" Version="4.3.1" />
<PackageReference Include="TestIt.ApiClient" Version="2.6.0" />
</ItemGroup>

Expand Down

0 comments on commit 6e5ae71

Please sign in to comment.