private string DownloadSamplePackage(PackageId packageId, NuGetVersion version, NuGetPackageDownloader nuGetPackageDownloader) { return(ExponentialRetry.ExecuteWithRetry( DownloadMostRecentSamplePackageFromPublicFeed, result => result != null, 3, () => ExponentialRetry.Timer(ExponentialRetry.Intervals), "Run command while retry transient restore error") .ConfigureAwait(false).GetAwaiter().GetResult()); string DownloadMostRecentSamplePackageFromPublicFeed() { try { return(nuGetPackageDownloader.DownloadPackageAsync( packageId, version, includePreview: true, packageSourceLocation: new PackageSourceLocation( sourceFeedOverrides: new[] { "https://api.nuget.org/v3/index.json" })).GetAwaiter() .GetResult()); } catch (Exception) { return(null); } } }
private string DownloadSamplePackage(PackageId packageId) { NuGetPackageDownloader nuGetPackageDownloader = new NuGetPackageDownloader(_tempDirectory, null, new MockFirstPartyNuGetPackageSigningVerifier(), _logger, restoreActionConfig: new RestoreActionConfig(NoCache: true)); return(ExponentialRetry.ExecuteWithRetry <string>( action: DownloadMostRecentSamplePackageFromPublicFeed, shouldStopRetry: result => result != null, maxRetryCount: 3, timer: () => ExponentialRetry.Timer(ExponentialRetry.Intervals), taskDescription: "Run command while retry transient restore error") .ConfigureAwait(false).GetAwaiter().GetResult()); string DownloadMostRecentSamplePackageFromPublicFeed() { try { return(nuGetPackageDownloader.DownloadPackageAsync( new PackageId("Microsoft.iOS.Ref"), null, includePreview: true, packageSourceLocation: new PackageSourceLocation( sourceFeedOverrides: new[] { "https://api.nuget.org/v3/index.json" })).GetAwaiter() .GetResult()); } catch (Exception) { return(null); } } }
public void ExponentialShouldRetryUntilSuccess() { var fakeAction = new FakeAction(5); ExponentialRetry.ExecuteWithRetry( fakeAction.Run, s => s == "success", 10, NoWaitTimer).Wait(); fakeAction.Count.Should().Be(5); }
public void ExponentialShouldNotRetryAfterFirstSucceess() { var fakeAction = new FakeAction(0); ExponentialRetry.ExecuteWithRetry( fakeAction.Run, s => s == "success", 10, NoWaitTimer).Wait(); fakeAction.Count.Should().Be(0); }
public void ExponentialShouldThrowAfterMaximumAmountReached() { var fakeAction = new FakeAction(10); Action a = () => ExponentialRetry.ExecuteWithRetry( fakeAction.Run, s => s == "success", 5, NoWaitTimer, "testing retry").Wait(); a.ShouldThrow <RetryFailedException>() .WithMessage("Retry failed for testing retry after 5 times with result: fail"); }
// https://aka.ms/netsdkinternal-certificate-rotate public void ItShouldHaveUpdateToDateCertificateSha() { NuGetPackageDownloader nuGetPackageDownloader = new NuGetPackageDownloader(_tempDirectory, null, new MockFirstPartyNuGetPackageSigningVerifier(), _logger, restoreActionConfig: new RestoreActionConfig(NoCache: true)); var samplePackage = ExponentialRetry.ExecuteWithRetry <string>( action: DownloadMostRecentSamplePackageFromPublicFeed, shouldStopRetry: result => result != null, maxRetryCount: 3, timer: () => ExponentialRetry.Timer(ExponentialRetry.Intervals), taskDescription: "Run command while retry transient restore error") .ConfigureAwait(false).GetAwaiter().GetResult(); string DownloadMostRecentSamplePackageFromPublicFeed() { try { return(nuGetPackageDownloader.DownloadPackageAsync( new PackageId("Microsoft.iOS.Ref"), null, includePreview: true, packageSourceLocation: new PackageSourceLocation( sourceFeedOverrides: new[] { "https://api.nuget.org/v3/index.json" })).GetAwaiter() .GetResult()); } catch (Exception) { return(null); } } var firstPartyNuGetPackageSigningVerifier = new FirstPartyNuGetPackageSigningVerifier(); string shaFromPackage = GetShaFromSamplePackage(samplePackage); firstPartyNuGetPackageSigningVerifier._firstPartyCertificateThumbprints.Contains(shaFromPackage).Should() .BeTrue( $"Add {shaFromPackage} to the _firstPartyCertificateThumbprints of FirstPartyNuGetPackageSigningVerifier class. More info https://aka.ms/netsdkinternal-certificate-rotate"); }