Skip to content

Commit 312ebd7

Browse files
Add support for .NET 8
- Add support for .NET 8, using preview 5. - Use built-in `TimeProvider` from NuGet instead of from source. - Simplify `TimeProviderExtensions`. - Remove usage of `MockTimeProvider`.
1 parent 67d72b0 commit 312ebd7

29 files changed

+169
-631
lines changed

Directory.Packages.props

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<Project>
22
<PropertyGroup>
3+
<MicrosoftExtensionsVersion>8.0.0-preview.5.23280.8</MicrosoftExtensionsVersion>
34
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
45
<PollyVersion>8.0.0-alpha.4</PollyVersion>
56
</PropertyGroup>
@@ -8,13 +9,16 @@
89
<PackageVersion Include="BenchmarkDotNet" Version="0.13.5" />
910
<PackageVersion Include="FluentAssertions" Version="6.11.0" />
1011
<PackageVersion Include="GitHubActionsTestLogger" Version="2.3.2" />
11-
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="1.0.0" />
12-
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
13-
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
14-
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
15-
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
16-
<PackageVersion Include="Microsoft.Extensions.Logging" Version="7.0.0" />
17-
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
12+
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
13+
<PackageVersion Include="Microsoft.Bcl.TimeProvider" Version="$(MicrosoftExtensionsVersion)" />
14+
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="$(MicrosoftExtensionsVersion)" />
15+
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="$(MicrosoftExtensionsVersion)" />
16+
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(MicrosoftExtensionsVersion)" />
17+
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="$(MicrosoftExtensionsVersion)" />
18+
<PackageVersion Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsVersion)" />
19+
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsVersion)" />
20+
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsVersion)" />
21+
<PackageVersion Include="Microsoft.Extensions.Options" Version="$(MicrosoftExtensionsVersion)" />
1822
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
1923
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
2024
<PackageVersion Include="MinVer" Version="4.3.0" />
@@ -27,23 +31,11 @@
2731
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.4.0.72892" />
2832
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.507" />
2933
<PackageVersion Include="System.ComponentModel.Annotations" Version="4.5.0" />
30-
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="7.0.0" />
31-
<PackageVersion Include="System.Threading.RateLimiting" Version="7.0.0" />
34+
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="$(MicrosoftExtensionsVersion)" />
35+
<PackageVersion Include="System.Threading.RateLimiting" Version="$(MicrosoftExtensionsVersion)" />
3236
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
3337
<PackageVersion Include="System.ValueTuple" Version="4.5.0" />
3438
<PackageVersion Include="xunit" Version="2.4.2" />
3539
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" />
3640
</ItemGroup>
37-
<ItemGroup Condition="$(TargetFramework) == 'net7.0'">
38-
<PackageVersion Include="Microsoft.Extensions.Options" Version="7.0.0" />
39-
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
40-
</ItemGroup>
41-
<ItemGroup Condition="$(TargetFramework) == 'net6.0'">
42-
<PackageVersion Include="Microsoft.Extensions.Options" Version="6.0.0" />
43-
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
44-
</ItemGroup>
45-
<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'netcoreapp3.1'))">
46-
<PackageVersion Include="Microsoft.Extensions.Options" Version="2.2.0" />
47-
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
48-
</ItemGroup>
4941
</Project>

bench/Polly.Benchmarks/Polly.Benchmarks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<IsPackable>false</IsPackable>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
5+
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
66
<Nullable>enable</Nullable>
77
<ProjectType>Benchmark</ProjectType>
88
<NoWarn>$(NoWarn);CA1822;SA1414;IDE0060</NoWarn>

bench/Polly.Core.Benchmarks/Polly.Core.Benchmarks.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net7.0</TargetFrameworks>
3+
<TargetFrameworks>net8.0;net7.0</TargetFrameworks>
4+
<RootNamespace>Polly</RootNamespace>
45
<ImplicitUsings>true</ImplicitUsings>
56
<ProjectType>Benchmark</ProjectType>
67
<Nullable>enable</Nullable>

eng/Analyzers.targets

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@
1212
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
1313
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
1414
<AnalysisLevel>latest</AnalysisLevel>
15+
<EnableNETAnalyzers>true</EnableNETAnalyzers>
16+
<!--
17+
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
18+
-->
1519
</PropertyGroup>
1620
</Project>

eng/stryker-config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
"block",
1919
"statement"
2020
],
21-
"target-framework": "net7.0",
21+
"target-framework": "net8.0",
2222
"thresholds": {
2323
"high": 100,
2424
"low": 100
2525
}
2626
}
27-
}
27+
}

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "7.0.304",
3+
"version": "8.0.100-preview.5.23303.2",
44
"allowPrerelease": false,
55
"rollForward": "latestMajor"
66
}

src/Polly.Core/Hedging/Controller/HedgingExecutionContext.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ public async ValueTask DisposeAsync()
130130

131131
using var delayTaskCancellation = CancellationTokenSource.CreateLinkedTokenSource(Snapshot.Context.CancellationToken);
132132

133+
#if NET8_0_OR_GREATER
134+
var delayTask = Task.Delay(hedgingDelay, _timeProvider, delayTaskCancellation.Token);
135+
#else
133136
var delayTask = _timeProvider.Delay(hedgingDelay, delayTaskCancellation.Token);
137+
#endif
134138
Task<Task> whenAnyHedgedTask = WaitForTaskCompetitionAsync();
135139
var completedTask = await Task.WhenAny(whenAnyHedgedTask, delayTask).ConfigureAwait(ContinueOnCapturedContext);
136140

@@ -141,7 +145,11 @@ public async ValueTask DisposeAsync()
141145

142146
// cancel the ongoing delay task
143147
// Stryker disable once boolean : no means to test this
148+
#if NET8_0_OR_GREATER
149+
await delayTaskCancellation.CancelAsync().ConfigureAwait(ContinueOnCapturedContext);
150+
#else
144151
delayTaskCancellation.Cancel(throwOnFirstException: false);
152+
#endif
145153

146154
await whenAnyHedgedTask.ConfigureAwait(ContinueOnCapturedContext);
147155

src/Polly.Core/Polly.Core.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net7.0;net6.0;netstandard2.0;net472;net462</TargetFrameworks>
4+
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.0;net472;net462</TargetFrameworks>
55
<AssemblyTitle>Polly.Core</AssemblyTitle>
66
<RootNamespace>Polly</RootNamespace>
77
<Nullable>enable</Nullable>
@@ -20,6 +20,7 @@
2020

2121
<ItemGroup>
2222
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Condition="!$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'netcoreapp3.1'))" />
23+
<PackageReference Include="Microsoft.Bcl.TimeProvider" Condition="!$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'net8.0'))"/>
2324
<PackageReference Include="System.Threading.Tasks.Extensions" Condition="!$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'netcoreapp3.1'))" />
2425
<PackageReference Include="System.ValueTuple" Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETFramework'" />
2526
<PackageReference Include="System.ComponentModel.Annotations" Condition="!$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'netcoreapp3.1'))" />

src/Polly.Core/Timeout/TimeoutResilienceStrategy.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Diagnostics.CodeAnalysis;
21
using Polly.Telemetry;
32

43
namespace Polly.Timeout;
@@ -23,7 +22,6 @@ public TimeoutResilienceStrategy(TimeoutStrategyOptions options, TimeProvider ti
2322

2423
public Func<OnTimeoutArguments, ValueTask>? OnTimeout { get; }
2524

26-
[ExcludeFromCodeCoverage]
2725
protected internal override async ValueTask<Outcome<TResult>> ExecuteCoreAsync<TResult, TState>(
2826
Func<ResilienceContext, TState, ValueTask<Outcome<TResult>>> callback,
2927
ResilienceContext context,
@@ -50,7 +48,7 @@ protected internal override async ValueTask<Outcome<TResult>> ExecuteCoreAsync<T
5048
var outcome = await ExecuteCallbackSafeAsync(callback, context, state).ConfigureAwait(context.ContinueOnCapturedContext);
5149
var isCancellationRequested = cancellationSource.IsCancellationRequested;
5250

53-
// execution is finished, cleanup
51+
// execution is finished, clean up
5452
context.CancellationToken = previousToken;
5553
#pragma warning disable CA1849 // Call async methods when in an async method, OK here as the callback is synchronous
5654
registration.Dispose();

0 commit comments

Comments
 (0)