Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit 1a0c11d

Browse files
committed
Allow package to exist in packages container when becoming to Available (#356)
Fix NuGet/NuGetGallery#5577
1 parent bc2d65d commit 1a0c11d

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

src/NuGet.Services.Validation.Orchestrator/ValidationOutcomeProcessor.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,23 @@ private async Task MoveFileToPublicStorageAndMarkPackageAsAvailable(PackageValid
177177
package.NormalizedVersion,
178178
validationSet.ValidationTrackingId);
179179
var packageStream = await _packageFileService.DownloadValidationPackageFileAsync(package);
180-
await _packageFileService.SavePackageFileAsync(package, packageStream);
180+
181+
try
182+
{
183+
await _packageFileService.SavePackageFileAsync(package, packageStream);
184+
}
185+
catch (InvalidOperationException)
186+
{
187+
// The package already exists in the packages container. This can happen if the DB commit below fails
188+
// and this flow is retried. We assume that the package content has not changed. Today there is no way
189+
// for the content to change. Hard deletes (the one way a package ID and version can get different
190+
// content) delete from both the packages and validating container so this can't be a mismatch.
191+
_logger.LogInformation(
192+
"Package already exists in packages container for {PackageId} {PackageVersion}, validation set {ValidationSetId}",
193+
package.PackageRegistration.Id,
194+
package.NormalizedVersion,
195+
validationSet.ValidationTrackingId);
196+
}
181197

182198
_logger.LogInformation("Marking package {PackageId} {PackageVersion}, validation set {ValidationSetId} as {PackageStatus} in DB",
183199
package.PackageRegistration.Id,

tests/NuGet.Services.Validation.Orchestrator.Tests/ValidationOutcomeProcessorFacts.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,37 @@ public async Task CopiesPackageToPublicStorageAndSendsEmailUponSuccess()
153153
.Verify(ms => ms.SendPackagePublishedMessage(It.IsAny<Package>()), Times.Once());
154154
}
155155

156+
[Fact]
157+
public async Task AllowsPackageAlreadyInPublicContainer()
158+
{
159+
AddValidation("validation1", ValidationStatus.Succeeded);
160+
Package.PackageStatusKey = PackageStatus.Validating;
161+
162+
var stream = new MemoryStream();
163+
164+
PackageFileServiceMock
165+
.Setup(pfs => pfs.DownloadValidationPackageFileAsync(Package))
166+
.ReturnsAsync(stream);
167+
168+
PackageFileServiceMock
169+
.Setup(pfs => pfs.SavePackageFileAsync(It.IsAny<Package>(), It.IsAny<Stream>()))
170+
.Throws(new InvalidOperationException("Duplicate!"));
171+
172+
var processor = CreateProcessor();
173+
await processor.ProcessValidationOutcomeAsync(ValidationSet, Package);
174+
175+
PackageFileServiceMock
176+
.Verify(pfs => pfs.DownloadValidationPackageFileAsync(Package), Times.Once);
177+
PackageFileServiceMock
178+
.Verify(pfs => pfs.SavePackageFileAsync(Package, stream), Times.Once);
179+
PackageServiceMock
180+
.Verify(ps => ps.UpdatePackageStatusAsync(Package, PackageStatus.Available, true), Times.Once);
181+
PackageFileServiceMock
182+
.Verify(pfs => pfs.DeleteValidationPackageFileAsync(Package.PackageRegistration.Id, Package.Version), Times.Once);
183+
MessageServiceMock
184+
.Verify(ms => ms.SendPackagePublishedMessage(Package), Times.Once);
185+
}
186+
156187
[Fact]
157188
public async Task DoesNotCopyPackageIfItsAvailable()
158189
{

0 commit comments

Comments
 (0)