From 1a8ace6702219f3b22fed1545fd54751e89b0a42 Mon Sep 17 00:00:00 2001 From: Andrei Grigorev Date: Tue, 27 Apr 2021 12:56:33 -0700 Subject: [PATCH] Agr blobs (#8517) * Added `Async` suffixes to method turned async --- src/NuGetGallery/App_Start/AppActivator.cs | 2 +- .../Lucene/CloudDownloadCountServiceRefreshJob.cs | 2 +- .../Services/CloudDownloadCountService.cs | 10 +++++----- .../Services/CloudDownloadCountServiceFacts.cs | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/NuGetGallery/App_Start/AppActivator.cs b/src/NuGetGallery/App_Start/AppActivator.cs index 0c6e24ac4c..1a437e7fe0 100644 --- a/src/NuGetGallery/App_Start/AppActivator.cs +++ b/src/NuGetGallery/App_Start/AppActivator.cs @@ -269,7 +269,7 @@ private static void BackgroundJobsPostStart(IAppConfiguration configuration) if (cloudDownloadCountService != null) { // Perform initial refresh + schedule new refreshes every 15 minutes - HostingEnvironment.QueueBackgroundWorkItem(_ => cloudDownloadCountService.Refresh()); + HostingEnvironment.QueueBackgroundWorkItem(_ => cloudDownloadCountService.RefreshAsync()); jobs.Add(new CloudDownloadCountServiceRefreshJob(TimeSpan.FromMinutes(15), cloudDownloadCountService)); } } diff --git a/src/NuGetGallery/Infrastructure/Lucene/CloudDownloadCountServiceRefreshJob.cs b/src/NuGetGallery/Infrastructure/Lucene/CloudDownloadCountServiceRefreshJob.cs index dbdb962521..840e754c51 100644 --- a/src/NuGetGallery/Infrastructure/Lucene/CloudDownloadCountServiceRefreshJob.cs +++ b/src/NuGetGallery/Infrastructure/Lucene/CloudDownloadCountServiceRefreshJob.cs @@ -19,7 +19,7 @@ public CloudDownloadCountServiceRefreshJob(TimeSpan interval, CloudDownloadCount public override Task Execute() { - return new Task(async () => { await _downloadCountService.Refresh(); }); + return new Task(async () => { await _downloadCountService.RefreshAsync(); }); } } } \ No newline at end of file diff --git a/src/NuGetGallery/Services/CloudDownloadCountService.cs b/src/NuGetGallery/Services/CloudDownloadCountService.cs index d5263acd0f..4380558d19 100644 --- a/src/NuGetGallery/Services/CloudDownloadCountService.cs +++ b/src/NuGetGallery/Services/CloudDownloadCountService.cs @@ -87,7 +87,7 @@ public bool TryGetDownloadCountForPackage(string id, string version, out int dow return false; } - public async Task Refresh() + public async Task RefreshAsync() { bool shouldRefresh = false; lock (_refreshLock) @@ -104,7 +104,7 @@ public async Task Refresh() try { var stopwatch = Stopwatch.StartNew(); - await RefreshCore(); + await RefreshCoreAsync(); stopwatch.Stop(); _telemetryService.TrackDownloadJsonRefreshDuration(stopwatch.ElapsedMilliseconds); @@ -148,19 +148,19 @@ protected virtual int CalculateSum(ConcurrentDictionary versions) /// This method is added for unit testing purposes. It can return a null stream if the blob does not exist /// and assumes the caller will properly dispose of the returned stream. /// - protected virtual async Task GetBlobStream() + protected virtual async Task GetBlobStreamAsync() { var blob = GetBlobReference(); return await blob.OpenReadIfExistsAsync(); } - private async Task RefreshCore() + private async Task RefreshCoreAsync() { try { // The data in downloads.v1.json will be an array of Package records - which has Id, Array of Versions and download count. // Sample.json : [["AutofacContrib.NSubstitute",["2.4.3.700",406],["2.5.0",137]],["Assman.Core",["2.0.7",138]].... - using (var blobStream = await GetBlobStream()) + using (var blobStream = await GetBlobStreamAsync()) { if (blobStream == null) { diff --git a/tests/NuGetGallery.Facts/Services/CloudDownloadCountServiceFacts.cs b/tests/NuGetGallery.Facts/Services/CloudDownloadCountServiceFacts.cs index 8d857a9a2b..2ab588890a 100644 --- a/tests/NuGetGallery.Facts/Services/CloudDownloadCountServiceFacts.cs +++ b/tests/NuGetGallery.Facts/Services/CloudDownloadCountServiceFacts.cs @@ -39,7 +39,7 @@ public async Task ReturnsZeroWhenIdDoesNotExist(string inputId, string contentId { // Arrange _content = $"[[\"{contentId}\",[\"4.6.0\",23],[\"4.6.2\",42]]"; - await _target.Refresh(); + await _target.RefreshAsync(); // Act var found = _target.TryGetDownloadCountForPackageRegistration(inputId, out var actual); @@ -59,7 +59,7 @@ public async Task ReturnsSumOfVersionsWhenIdExists(string inputId, string conten { // Arrange _content = $"[[\"{contentId}\",[\"4.6.0\",23],[\"4.6.2\",42]]"; - await _target.Refresh(); + await _target.RefreshAsync(); // Act var found = _target.TryGetDownloadCountForPackageRegistration(inputId, out var actual); @@ -94,7 +94,7 @@ private async Task LoadNewVersionsAsync(string id, TimeSpan duration) iteration++; var version = $"0.0.0-beta{iteration}"; _content = $"[[\"{id}\",[\"{version}\",1]]"; - await _target.Refresh(); + await _target.RefreshAsync(); await Task.Delay(5); } } @@ -117,7 +117,7 @@ public class TheTryGetDownloadCountForPackageMethod : BaseFacts public async Task ReturnsZeroWhenVersionDoesNotExist() { // Arrange - await _target.Refresh(); + await _target.RefreshAsync(); // Act var found = _target.TryGetDownloadCountForPackage("NuGet.Versioning", "9.9.9", out var actual); @@ -131,7 +131,7 @@ public async Task ReturnsZeroWhenVersionDoesNotExist() public async Task ReturnsCountWhenVersionExists() { // Arrange - await _target.Refresh(); + await _target.RefreshAsync(); // Act var found = _target.TryGetDownloadCountForPackage("NuGet.Versioning", "4.6.0", out var actual); @@ -188,7 +188,7 @@ protected override int CalculateSum(ConcurrentDictionary versions) return _baseFacts._calculateSum(versions); } - protected override Task GetBlobStream() + protected override Task GetBlobStreamAsync() { if (_baseFacts._content == null) {