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

Add banned API analyzers and fix time zone issue #1651

Merged
merged 4 commits into from
Sep 28, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* Update docs source by [@martincostello](https://github.com/martincostello) in https://github.com/App-vNext/Polly/pull/1641
* Stabilize `AddHedging_IntegrationTest` test by [@martintmk](https://github.com/martintmk) in https://github.com/App-vNext/Polly/pull/1644
* Release v8 docs by [@martintmk](https://github.com/martintmk) in https://github.com/App-vNext/Polly/pull/1599
* Add banned API analyzers and fix time zone issue by [@martincostello](https://github.com/martincostello) and [@IEvangelist](https://github.com/IEvangelist) in https://github.com/App-vNext/Polly/pull/1651

## 8.0.0-beta.2

Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.3.3" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="$(MicrosoftExtensionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="$(MicrosoftExtensionsVersion)" />
Expand Down
2 changes: 2 additions & 0 deletions eng/Analyzers.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<Project>
<ItemGroup Label="Analyzers">
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)analyzers\BannedSymbols.txt" Condition=" '$(IsTestProject)' != 'true' " Visible="false" />
<AdditionalFiles Include="$(MsBuildThisFileDirectory)analyzers\Stylecop.json" Visible="false" />
<EditorConfigFiles Include="$(MsBuildThisFileDirectory)analyzers\Stylecop.globalconfig" />
<EditorConfigFiles Include="$(MsBuildThisFileDirectory)analyzers\$(ProjectType).globalconfig" />
Expand Down
5 changes: 5 additions & 0 deletions eng/analyzers/BannedSymbols.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
P:System.DateTime.Now; Use TimeProvider.GetLocalNow().DateTime instead.
P:System.DateTime.Today; Use TimeProvider.GetLocalNow().DateTime.Date instead.
P:System.DateTimeOffset.Now; Use TimeProvider.GetLocalNow() instead.
P:System.DateTimeOffset.Today; Use TimeProvider.GetLocalNow().Date instead.
M:System.DateTimeOffset.op_Implicit(System.DateTime); Do not implicitly cast DateTime to DateTimeOffset.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ internal static async ValueTask ExecuteScheduledTaskAsync(Task? task, Resilience

private static bool IsDateTimeOverflow(DateTimeOffset utcNow, TimeSpan breakDuration)
{
TimeSpan maxDifference = DateTime.MaxValue - utcNow;
TimeSpan maxDifference = DateTimeOffset.MaxValue - utcNow;

// stryker disable once equality : no means to test this
return breakDuration > maxDifference;
Expand Down
2 changes: 1 addition & 1 deletion src/Polly/RateLimit/LockFreeTokenBucketRateLimiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal sealed class LockFreeTokenBucketRateLimiter : IRateLimiter
#endif

/// <summary>
/// Creates an instance of <see cref="LockFreeTokenBucketRateLimiter"/>
/// Initializes a new instance of the <see cref="LockFreeTokenBucketRateLimiter"/> class.
/// </summary>
/// <param name="onePer">How often one execution is permitted.</param>
/// <param name="bucketCapacity">The capacity of the token bucket.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public async Task OnActionFailureAsync_EnsureBreakDurationNotOverflow(bool overf
using var controller = CreateController();
var shouldBreak = true;
await TransitionToState(controller, CircuitState.HalfOpen);
var utcNow = DateTime.MaxValue - _options.BreakDuration;
var utcNow = DateTimeOffset.MaxValue - _options.BreakDuration;
if (overflow)
{
utcNow += TimeSpan.FromMilliseconds(10);
Expand Down