From 3a835a7dc211f0c9f340cb953c365df82cfb9341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wola=C5=84ski?= Date: Wed, 18 Dec 2019 13:34:09 +0100 Subject: [PATCH 1/4] Fixed DecorrelatedJitterBackoffV2 parameter in doc (#16) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 756ea62..fee44c0 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ One way to address this is to add some randomness to the wait delay. This will c Following [exploration by Polly community members](https://github.com/App-vNext/Polly/issues/530), we now recommend a new jitter formula characterised by very smooth and even distribution of retry intervals, a well-controlled median initial retry delay, and broadly exponential backoff. - var delay = Backoff.DecorrelatedJitterBackoffV2(medianFirstDelay: TimeSpan.FromSeconds(1), retryCount: 5); + var delay = Backoff.DecorrelatedJitterBackoffV2(medianFirstRetryDelay: TimeSpan.FromSeconds(1), retryCount: 5); var retryPolicy = Policy .Handle() From bd4386a1fc9163322bea12829cfec9bc07d890c3 Mon Sep 17 00:00:00 2001 From: Dylan Reisenberger Date: Thu, 26 Sep 2019 20:29:30 +0100 Subject: [PATCH 2/4] Add range tests on AwsDecorrelatedJitter (#15) --- CHANGELOG.md | 3 ++ .../AwsDecorrelatedJitterBackoffSpecs.cs | 15 +++++----- .../DecorrelatedJitterBackoffV2Specs.cs | 29 ++----------------- .../Utilities/TimeSpanExtensions.cs | 14 +++++++++ 4 files changed, 27 insertions(+), 34 deletions(-) create mode 100644 src/Polly.Contrib.WaitAndRetry.Specs/Utilities/TimeSpanExtensions.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 69277f4..af85ce1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Polly.Contrib.WaitAndRetry changelog +## vNext +- Extend tests on original jitter policy to cover range of seed values + ## 1.0.0 - Launch version diff --git a/src/Polly.Contrib.WaitAndRetry.Specs/AwsDecorrelatedJitterBackoffSpecs.cs b/src/Polly.Contrib.WaitAndRetry.Specs/AwsDecorrelatedJitterBackoffSpecs.cs index 53f0dac..2604707 100644 --- a/src/Polly.Contrib.WaitAndRetry.Specs/AwsDecorrelatedJitterBackoffSpecs.cs +++ b/src/Polly.Contrib.WaitAndRetry.Specs/AwsDecorrelatedJitterBackoffSpecs.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Polly.Contrib.WaitAndRetry.Specs.Utilities; using Xunit; namespace Polly.Contrib.WaitAndRetry.Specs @@ -108,21 +109,22 @@ public void Backoff_WithFastFirstEqualToTrue_ResultIsZero() } else { - timeSpan.Should().BeGreaterOrEqualTo(minDelay); - timeSpan.Should().BeLessOrEqualTo(maxDelay); + timeSpan.ShouldBeBetweenOrEqualTo(minDelay, maxDelay); } } } - [Fact] - public void Backoff_ResultIsInRange() + public static IEnumerable SeedRange => Enumerable.Range(0, 1000).Select(o => new object[] { o }).ToArray(); + + [Theory] + [MemberData(nameof(SeedRange))] + public void Backoff_ResultIsInRange(int seed) { // Arrange var minDelay = TimeSpan.FromMilliseconds(10); var maxDelay = TimeSpan.FromMilliseconds(100); const int retryCount = 3; const bool fastFirst = false; - const int seed = 100; // Act IEnumerable result = Backoff.AwsDecorrelatedJitterBackoff(minDelay, maxDelay, retryCount, seed, fastFirst); @@ -134,8 +136,7 @@ public void Backoff_ResultIsInRange() foreach (TimeSpan timeSpan in result) { - timeSpan.Should().BeGreaterOrEqualTo(minDelay); - timeSpan.Should().BeLessOrEqualTo(maxDelay); + timeSpan.ShouldBeBetweenOrEqualTo(minDelay, maxDelay); } } } diff --git a/src/Polly.Contrib.WaitAndRetry.Specs/DecorrelatedJitterBackoffV2Specs.cs b/src/Polly.Contrib.WaitAndRetry.Specs/DecorrelatedJitterBackoffV2Specs.cs index ce14d6f..fc5a1ff 100644 --- a/src/Polly.Contrib.WaitAndRetry.Specs/DecorrelatedJitterBackoffV2Specs.cs +++ b/src/Polly.Contrib.WaitAndRetry.Specs/DecorrelatedJitterBackoffV2Specs.cs @@ -100,37 +100,12 @@ public void Backoff_WithFastFirstEqualToTrue_ResultIsZero() } } } - - [Fact] - public void Backoff_ResultIsInRange() - { - // Arrange - var medianFirstDelay = TimeSpan.FromSeconds(1); - const int retryCount = 6; - const bool fastFirst = false; - const int seed = 23456; - - // Act - IEnumerable result = Backoff.DecorrelatedJitterBackoffV2(medianFirstDelay, retryCount, seed, fastFirst); - - // Assert - result.Should().NotBeNull(); - result = result.ToList(); - result.Should().HaveCount(retryCount); - - int t = 0; - foreach (TimeSpan timeSpan in result) - { - t++; - AssertOnRetryDelayForTry(t, timeSpan, medianFirstDelay); - } - } - + public static IEnumerable SeedRange => Enumerable.Range(0, 1000).Select(o => new object[] {o}).ToArray(); [Theory] [MemberData(nameof(SeedRange))] - public void Backoff_ResultIsInRange_WideTest(int seed) + public void Backoff_ResultIsInRange(int seed) { // Arrange var medianFirstDelay = TimeSpan.FromSeconds(3); diff --git a/src/Polly.Contrib.WaitAndRetry.Specs/Utilities/TimeSpanExtensions.cs b/src/Polly.Contrib.WaitAndRetry.Specs/Utilities/TimeSpanExtensions.cs new file mode 100644 index 0000000..037c276 --- /dev/null +++ b/src/Polly.Contrib.WaitAndRetry.Specs/Utilities/TimeSpanExtensions.cs @@ -0,0 +1,14 @@ +using System; +using FluentAssertions; + +namespace Polly.Contrib.WaitAndRetry.Specs.Utilities +{ + public static class TimeSpanExtensions + { + public static void ShouldBeBetweenOrEqualTo(this TimeSpan timeSpan, TimeSpan minDelay, TimeSpan maxDelay) + { + timeSpan.Should().BeGreaterOrEqualTo(minDelay); + timeSpan.Should().BeLessOrEqualTo(maxDelay); + } + } +} \ No newline at end of file From 22a0e460a2e00a1d0f734a668f3cc9e92819d9c4 Mon Sep 17 00:00:00 2001 From: reisenberger Date: Thu, 9 Jan 2020 19:53:48 +0000 Subject: [PATCH 3/4] Modernise build and add SourceLink --- CHANGELOG.md | 4 +- build.cake | 85 +++++-------------- .../Polly.Contrib.WaitAndRetry.Specs.csproj | 4 +- src/Polly.Contrib.WaitAndRetry.nuspec | 34 -------- .../Polly.Contrib.WaitAndRetry.csproj | 49 ++++++----- 5 files changed, 53 insertions(+), 123 deletions(-) delete mode 100644 src/Polly.Contrib.WaitAndRetry.nuspec diff --git a/CHANGELOG.md b/CHANGELOG.md index af85ce1..58a15cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ # Polly.Contrib.WaitAndRetry changelog -## vNext +## 1.1.0 - Extend tests on original jitter policy to cover range of seed values +- Modernise build +- Add SourceLink support ## 1.0.0 - Launch version diff --git a/build.cake b/build.cake index a9af6ea..ec7f75f 100644 --- a/build.cake +++ b/build.cake @@ -11,7 +11,6 @@ var configuration = Argument("configuration", "Release"); #Tool "xunit.runner.console" #Tool "GitVersion.CommandLine" -#Tool "Brutal.Dev.StrongNameSigner" ////////////////////////////////////////////////////////////////////// // EXTERNAL NUGET LIBRARIES @@ -26,22 +25,16 @@ var configuration = Argument("configuration", "Release"); /////////////////////////////////////////////////////////////////////////////// var projectName = "Polly.Contrib.WaitAndRetry"; -var keyName = projectName + ".snk"; var solutions = GetFiles("./**/*.sln"); var solutionPaths = solutions.Select(solution => solution.GetDirectory()); var srcDir = Directory("./src"); -var buildDir = Directory("./build"); var artifactsDir = Directory("./artifacts"); var testResultsDir = artifactsDir + Directory("test-results"); // NuGet -var nuspecFilename = projectName + ".nuspec"; -var nuspecSrcFile = srcDir + File(nuspecFilename); -var nuspecDestFile = buildDir + File(nuspecFilename); var nupkgDestDir = artifactsDir + Directory("nuget-package"); -var snkFile = srcDir + File(keyName); // Gitversion var gitVersionPath = ToolsExePath("GitVersion.exe"); @@ -54,9 +47,6 @@ string appveyorBuildNumber; string assemblyVersion; string assemblySemver; -// StrongNameSigner -var strongNameSignerPath = ToolsExePath("StrongNameSigner.Console.exe"); - /////////////////////////////////////////////////////////////////////////////// // INNER CLASSES /////////////////////////////////////////////////////////////////////////////// @@ -71,10 +61,10 @@ class GitVersionConfigYaml Setup(_ => { - Information("=============================="); - Information("Starting the cake build script"); - Information("Building: " + projectName); - Information("=============================="); + Information("=============================="); + Information("Starting the cake build script"); + Information("Building: " + projectName); + Information("=============================="); }); Teardown(_ => @@ -90,7 +80,6 @@ Task("__Clean") .Does(() => { DirectoryPath[] cleanDirectories = new DirectoryPath[] { - buildDir, testResultsDir, nupkgDestDir, artifactsDir @@ -103,8 +92,7 @@ Task("__Clean") foreach(var path in solutionPaths) { Information("Cleaning {0}", path); - CleanDirectories(path + "/**/bin/" + configuration); - CleanDirectories(path + "/**/obj/" + configuration); + DotNetCoreClean(path.ToString()); } }); @@ -114,7 +102,7 @@ Task("__RestoreNugetPackages") foreach(var solution in solutions) { Information("Restoring NuGet Packages for {0}", solution); - NuGetRestore(solution); + DotNetCoreRestore(solution.ToString()); } }); @@ -154,7 +142,9 @@ Task("__UpdateAssemblyVersionInformation") Information("FullSemVer -> {0}", gitVersionOutput["FullSemVer"]); Information("AssemblySemVer -> {0}", gitVersionOutput["AssemblySemVer"]); - appveyorBuildNumber = gitVersionOutput["FullSemVer"].ToString(); + appveyorBuildNumber = gitVersionOutput["BranchName"].ToString().Equals("master", StringComparison.OrdinalIgnoreCase) + ? gitVersionOutput["FullSemVer"].ToString() + : gitVersionOutput["InformationalVersion"].ToString(); nugetVersion = gitVersionOutput["NuGetVersion"].ToString(); assemblyVersion = gitVersionOutput["Major"].ToString() + ".0.0.0"; assemblySemver = gitVersionOutput["AssemblySemVer"].ToString(); @@ -210,13 +200,14 @@ Task("__BuildSolutions") { Information("Building {0}", solution); - MSBuild(solution, settings => - settings - .SetConfiguration(configuration) - .WithProperty("TreatWarningsAsErrors", "true") - .UseToolVersion(MSBuildToolVersion.VS2017) - .SetVerbosity(Verbosity.Minimal) - .SetNodeReuse(false)); + var dotNetCoreBuildSettings = new DotNetCoreBuildSettings { + Configuration = configuration, + Verbosity = DotNetCoreVerbosity.Minimal, + NoRestore = true, + MSBuildSettings = new DotNetCoreMSBuildSettings { TreatAllWarningsAs = MSBuildTreatAllWarningsAs.Error } + }; + + DotNetCoreBuild(solution.ToString(), dotNetCoreBuildSettings); } }); @@ -231,35 +222,6 @@ Task("__RunTests") } }); -Task("__CopyOutputToNugetFolder") - .Does(() => -{ - var sourceDir = srcDir + Directory(projectName) + Directory("bin") + Directory(configuration); - - var destDir = buildDir + Directory("lib"); - - Information("Copying {0} -> {1}.", sourceDir, destDir); - CopyDirectory(sourceDir, destDir); - - CopyFile(nuspecSrcFile, nuspecDestFile); -}); - -Task("__StronglySignAssemblies") - .Does(() => -{ - //see: https://github.com/brutaldev/StrongNameSigner - var strongNameSignerSettings = new ProcessSettings() - .WithArguments(args => args - .Append("-in") - .AppendQuoted(buildDir) - .Append("-k") - .AppendQuoted(snkFile) - .Append("-l") - .AppendQuoted("Changes")); - - StartProcess(strongNameSignerPath, strongNameSignerSettings); -}); - Task("__CreateSignedNugetPackage") .Does(() => { @@ -267,14 +229,13 @@ Task("__CreateSignedNugetPackage") Information("Building {0}.{1}.nupkg", packageName, nugetVersion); - var nuGetPackSettings = new NuGetPackSettings { - Id = packageName, - Title = packageName, - Version = nugetVersion, + var dotNetCorePackSettings = new DotNetCorePackSettings { + Configuration = configuration, + NoBuild = true, OutputDirectory = nupkgDestDir }; - NuGetPack(nuspecDestFile, nuGetPackSettings); + DotNetCorePack($@"{srcDir}\{projectName}.sln", dotNetCorePackSettings); }); ////////////////////////////////////////////////////////////////////// @@ -289,8 +250,6 @@ Task("Build") .IsDependentOn("__UpdateAppVeyorBuildNumber") .IsDependentOn("__BuildSolutions") .IsDependentOn("__RunTests") - .IsDependentOn("__CopyOutputToNugetFolder") - .IsDependentOn("__StronglySignAssemblies") .IsDependentOn("__CreateSignedNugetPackage"); /////////////////////////////////////////////////////////////////////////////// @@ -311,6 +270,6 @@ RunTarget(target); ////////////////////////////////////////////////////////////////////// string ToolsExePath(string exeFileName) { - var exePath = System.IO.Directory.GetFiles(@".\Tools", exeFileName, SearchOption.AllDirectories).FirstOrDefault(); + var exePath = System.IO.Directory.GetFiles(@"./tools", exeFileName, SearchOption.AllDirectories).FirstOrDefault(); return exePath; } diff --git a/src/Polly.Contrib.WaitAndRetry.Specs/Polly.Contrib.WaitAndRetry.Specs.csproj b/src/Polly.Contrib.WaitAndRetry.Specs/Polly.Contrib.WaitAndRetry.Specs.csproj index 1a1ac7d..c7acda0 100644 --- a/src/Polly.Contrib.WaitAndRetry.Specs/Polly.Contrib.WaitAndRetry.Specs.csproj +++ b/src/Polly.Contrib.WaitAndRetry.Specs/Polly.Contrib.WaitAndRetry.Specs.csproj @@ -1,7 +1,7 @@  - netcoreapp1.1;netcoreapp2.0;net462;net472 + netcoreapp1.1;netcoreapp2.0;net461;net472 @@ -19,7 +19,7 @@ - + diff --git a/src/Polly.Contrib.WaitAndRetry.nuspec b/src/Polly.Contrib.WaitAndRetry.nuspec deleted file mode 100644 index b23e205..0000000 --- a/src/Polly.Contrib.WaitAndRetry.nuspec +++ /dev/null @@ -1,34 +0,0 @@ - - - - App vNext - Grant Dickinson, App vNext - - Polly.Contrib.WaitAndRetry is an extension library for Polly containing helper methods for a variety of wait-and-retry strategies. - - en-US - BSD-3-Clause - https://raw.github.com/App-vNext/Polly/master/Polly.png - https://github.com/Polly-Contrib/Polly.Contrib.WaitAndRetry - Copyright © 2019, App vNext and contributors - - 1.0.0 - --------------------- - - Launch version - - - - - - - - - - - - - - - - - diff --git a/src/Polly.Contrib.WaitAndRetry/Polly.Contrib.WaitAndRetry.csproj b/src/Polly.Contrib.WaitAndRetry/Polly.Contrib.WaitAndRetry.csproj index c6f667e..cc85b77 100644 --- a/src/Polly.Contrib.WaitAndRetry/Polly.Contrib.WaitAndRetry.csproj +++ b/src/Polly.Contrib.WaitAndRetry/Polly.Contrib.WaitAndRetry.csproj @@ -1,49 +1,52 @@ - netstandard1.1;netstandard2.0 + 8.0 Polly.Contrib.WaitAndRetry Polly.Contrib.WaitAndRetry false - - - - 1.0.0-bumptov100-0001 + 1.1.0-v110_moderniseBuild 1.0.0.0 - 1.0.0.0 - 1.0.0.0 - 1.0.0-bumptov100-0001 - - - + 1.1.0.0 + 1.1.0.0 + 1.1.0-v110_moderniseBuild Grant Dickinson, App vNext App vNext - Copyright (c) 2019, App vNext and contributors - - - + Copyright (c) 2020, App vNext and contributors + Polly.Contrib.WaitAndRetry is an extension library for Polly containing helper methods for a variety of wait-and-retry strategies. en-US true true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - - - full + + true + true + snupkg - + + + - pdbonly true - 1.6.1 - + + - + + en-US + Polly.Contrib.WaitAndRetry + BSD-3-Clause + https://raw.github.com/App-vNext/Polly/master/Polly.png + https://github.com/Polly-Contrib/Polly.Contrib.WaitAndRetry + Resilience Resiliency Fault-tolerance Transient-fault-handling Retry Retry-intervals Jitter + See https://github.com/Polly-Contrib/Polly.Contrib.WaitAndRetry/blob/master/CHANGELOG.md for details + From 32d50e9496cc79b93a1c92987d0fd40be50c9a5f Mon Sep 17 00:00:00 2001 From: Dylan Reisenberger Date: Thu, 9 Jan 2020 21:11:30 +0000 Subject: [PATCH 4/4] Fix build --- .../Polly.Contrib.WaitAndRetry.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Polly.Contrib.WaitAndRetry/Polly.Contrib.WaitAndRetry.csproj b/src/Polly.Contrib.WaitAndRetry/Polly.Contrib.WaitAndRetry.csproj index cc85b77..4fefd00 100644 --- a/src/Polly.Contrib.WaitAndRetry/Polly.Contrib.WaitAndRetry.csproj +++ b/src/Polly.Contrib.WaitAndRetry/Polly.Contrib.WaitAndRetry.csproj @@ -5,11 +5,11 @@ Polly.Contrib.WaitAndRetry Polly.Contrib.WaitAndRetry false - 1.1.0-v110_moderniseBuild + 1.1.0 1.0.0.0 1.1.0.0 1.1.0.0 - 1.1.0-v110_moderniseBuild + 1.1.0 Grant Dickinson, App vNext App vNext Copyright (c) 2020, App vNext and contributors