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

Port fixes from .NET 9 testing #2056

Merged
merged 7 commits into from
Apr 12, 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
7 changes: 4 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project>
<PropertyGroup>
<MicrosoftExtensionsVersion>8.0.0</MicrosoftExtensionsVersion>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<PollyVersion>8.3.0</PollyVersion>
<PollyVersion>8.3.1</PollyVersion>
<MicrosoftExtensionsVersion>8.0.0</MicrosoftExtensionsVersion>
<MicrosoftExtensionsTimeProviderVersion>8.4.0</MicrosoftExtensionsTimeProviderVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="coverlet.msbuild" Version="6.0.1" />
Expand All @@ -22,7 +23,7 @@
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="$(MicrosoftExtensionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(MicrosoftExtensionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.TimeProvider.Testing" Version="8.3.0" />
<PackageVersion Include="Microsoft.Extensions.TimeProvider.Testing" Version="$(MicrosoftExtensionsTimeProviderVersion)" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="MinVer" Version="4.3.0" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
Expand Down
6 changes: 1 addition & 5 deletions src/Polly.Core/Polly.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
<LegacySupport>true</LegacySupport>
<InjectSharedSources>true</InjectSharedSources>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
martintmk marked this conversation as resolved.
Show resolved Hide resolved
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<IsAotCompatible>true</IsAotCompatible>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>

<PropertyGroup>
Expand Down
8 changes: 7 additions & 1 deletion src/Polly.Core/Utils/TypeNameFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public static string Format(Type type)
return type.Name;
}

return $"{type.Name.Substring(0, type.Name.Length - GenericSuffixLength)}<{Format(args[0])}>";
#if NET6_0_OR_GREATER
var nameNoAirity = type.Name[..(type.Name.Length - GenericSuffixLength)];
#else
var nameNoAirity = type.Name.Substring(0, type.Name.Length - GenericSuffixLength);
#endif

return $"{nameNoAirity}<{Format(args[0])}>";
}
}
6 changes: 1 addition & 5 deletions src/Polly.Extensions/Polly.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@
<MutationScore>100</MutationScore>
<LegacySupport>true</LegacySupport>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<IsAotCompatible>true</IsAotCompatible>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>

<PropertyGroup>
Expand Down
6 changes: 1 addition & 5 deletions src/Polly.RateLimiting/Polly.RateLimiting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@
<MutationScore>100</MutationScore>
<LegacySupport>true</LegacySupport>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<IsAotCompatible>true</IsAotCompatible>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>

<PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions src/Polly/Utilities/KeyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ internal static class KeyHelper
private const int GuidPartLength = 8;

public static string GuidPart() =>
#if NET6_0_OR_GREATER
Guid.NewGuid().ToString()[..GuidPartLength];
martincostello marked this conversation as resolved.
Show resolved Hide resolved
#else
Guid.NewGuid().ToString().Substring(0, GuidPartLength);
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ public async Task TryWaitForCompletedExecutionAsync_SynchronousExecution_Ok()
}

var task = context.TryWaitForCompletedExecutionAsync(System.Threading.Timeout.InfiniteTimeSpan).AsTask();
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
task.Wait(20).Should().BeFalse();
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
_timeProvider.Advance(TimeSpan.FromDays(1));
await task;
context.Tasks[0].AcceptOutcome();
Expand All @@ -162,7 +164,9 @@ public async Task TryWaitForCompletedExecutionAsync_HedgedExecution_Ok()
var hedgingDelay = TimeSpan.FromSeconds(5);
var count = _timeProvider.TimerEntries.Count;
var task = context.TryWaitForCompletedExecutionAsync(hedgingDelay).AsTask();
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
task.Wait(20).Should().BeFalse();
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
_timeProvider.TimerEntries.Should().HaveCount(count + 1);
_timeProvider.TimerEntries.Last().Delay.Should().Be(hedgingDelay);
_timeProvider.Advance(TimeSpan.FromDays(1));
Expand Down Expand Up @@ -382,7 +386,9 @@ public async Task Complete_EnsurePendingTasksCleaned()
await context.TryWaitForCompletedExecutionAsync(System.Threading.Timeout.InfiniteTimeSpan);

var pending = context.Tasks[1].ExecutionTaskSafe!;
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
pending.Wait(10).Should().BeFalse();
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method

context.Tasks[0].AcceptOutcome();
await context.DisposeAsync();
Expand Down
1 change: 1 addition & 0 deletions test/Polly.Core.Tests/Polly.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Bcl.TimeProvider" VersionOverride="8.0.1" />
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" />
<PackageReference Include="Polly.Contrib.WaitAndRetry" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions test/Polly.Core.Tests/Simmy/ChaosStrategyConstantsTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Polly.Simmy;

namespace Polly.Core.Tests;

public class ChaosStrategyConstantsTests
{
[Fact]
Expand Down