Skip to content

Commit 2cf936f

Browse files
authored
[Symbol server]Address UI fixes and fix re-upload on failed validation issues for Symbol Server (#6627)
1 parent a053203 commit 2cf936f

3 files changed

Lines changed: 80 additions & 8 deletions

File tree

src/NuGetGallery/Services/SymbolPackageUploadService.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public async Task<PackageCommitResult> CreateAndUploadSymbolsPackage(Package pac
146146

147147
Stream symbolPackageFile = symbolPackageStream.AsSeekableStream();
148148

149+
var previousSymbolsPackage = package.LatestSymbolPackage();
149150
var symbolPackage = _symbolPackageService.CreateSymbolPackage(package, packageStreamMetadata);
150151

151152
await _validationService.StartValidationAsync(symbolPackage);
@@ -161,6 +162,16 @@ public async Task<PackageCommitResult> CreateAndUploadSymbolsPackage(Package pac
161162
{
162163
if (symbolPackage.StatusKey == PackageStatus.Validating)
163164
{
165+
// If the last uploaded symbol package has failed validation, it will leave the snupkg in the
166+
// validations container. We could possibly overwrite it, but that might introduce a concurrency
167+
// issue on multiple snupkg uploads with a prior failed validation. The best thing to do would be
168+
// to delete the failed validation snupkg from validations container and then proceed with normal
169+
// upload.
170+
if (previousSymbolsPackage != null && previousSymbolsPackage.StatusKey == PackageStatus.FailedValidation)
171+
{
172+
await DeleteSymbolsPackageAsync(previousSymbolsPackage);
173+
}
174+
164175
await _symbolPackageFileService.SaveValidationPackageFileAsync(symbolPackage.Package, symbolPackageFile);
165176
}
166177
else if (symbolPackage.StatusKey == PackageStatus.Available)
@@ -239,7 +250,13 @@ public async Task DeleteSymbolsPackageAsync(SymbolPackage symbolPackage)
239250
throw new ArgumentNullException(nameof(symbolPackage));
240251
}
241252

242-
if (await _symbolPackageFileService.DoesPackageFileExistAsync(symbolPackage.Package))
253+
if (symbolPackage.StatusKey == PackageStatus.FailedValidation
254+
&& await _symbolPackageFileService.DoesValidationPackageFileExistAsync(symbolPackage.Package))
255+
{
256+
await _symbolPackageFileService.DeleteValidationPackageFileAsync(symbolPackage.Id, symbolPackage.Version);
257+
}
258+
else if (symbolPackage.StatusKey == PackageStatus.Available
259+
&& await _symbolPackageFileService.DoesPackageFileExistAsync(symbolPackage.Package))
243260
{
244261
await _symbolPackageFileService.DeletePackageFileAsync(symbolPackage.Id, symbolPackage.Version);
245262
}

src/NuGetGallery/Views/Packages/DisplayPackage.cshtml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,8 @@
275275
{
276276
@ViewHelpers.AlertWarning(
277277
@<text>
278-
The symbols for this package have not been indexed yet. They are not available
279-
for download from the NuGet.org symbol server. Symbols will be indexed and will
280-
be available for download after both validation and indexing are complete.
278+
<strong>The symbols for this package have not been indexed yet.</strong> They are not available
279+
for download from the NuGet.org symbol server. Symbols will be available for download after both validation and indexing are complete.
281280
Symbols validation and indexing may take up to an hour. <a href="https://aka.ms/NuGetSymbolsPackageValidation">Read more</a>.
282281
</text>
283282
)
@@ -721,10 +720,13 @@
721720
<a href="@Url.RevalidatePackage(Model)">Revalidate package</a>
722721
</li>
723722

724-
<li>
725-
<i class="ms-Icon ms-Icon--Refresh" aria-hidden="true"></i>
726-
<a href="@Url.RevalidateSymbolsPackage(Model)">Revalidate symbols</a>
727-
</li>
723+
if (Model.LatestSymbolsPackage != null)
724+
{
725+
<li>
726+
<i class="ms-Icon ms-Icon--Refresh" aria-hidden="true"></i>
727+
<a href="@Url.RevalidateSymbolsPackage(Model)">Revalidate symbols</a>
728+
</li>
729+
}
728730
}
729731

730732
@if (User.IsAdministrator() && Config.Current.AsynchronousPackageValidationEnabled)

tests/NuGetGallery.Facts/Services/SymbolPackageUploadServiceFacts.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,59 @@ public async Task WillReturnConflictIfFileExistsInContainer()
264264
symbolPackageFileService.Verify(x => x.SavePackageFileAsync(package, It.IsAny<Stream>(), It.IsAny<bool>()), Times.Once);
265265
}
266266

267+
[Fact]
268+
public async Task WillDeleteFailedValidationSnupkg()
269+
{
270+
// Arrange
271+
var symbolPackageService = new Mock<ISymbolPackageService>();
272+
symbolPackageService
273+
.Setup(x => x.CreateSymbolPackage(It.IsAny<Package>(), It.IsAny<PackageStreamMetadata>()))
274+
.Returns((Package package1, PackageStreamMetadata streamMetadata) =>
275+
{
276+
var symbolPackage = new SymbolPackage()
277+
{
278+
Package = package1,
279+
PackageKey = package1.Key,
280+
Created = DateTime.UtcNow,
281+
StatusKey = PackageStatus.Validating
282+
};
283+
284+
return symbolPackage;
285+
})
286+
.Verifiable();
287+
288+
var symbolPackageFileService = new Mock<ISymbolPackageFileService>();
289+
symbolPackageFileService
290+
.Setup(x => x.DoesValidationPackageFileExistAsync(It.IsAny<Package>()))
291+
.ReturnsAsync(true)
292+
.Verifiable();
293+
symbolPackageFileService
294+
.Setup(x => x.DeleteValidationPackageFileAsync(It.IsAny<string>(), It.IsAny<string>()))
295+
.Completes()
296+
.Verifiable();
297+
symbolPackageFileService
298+
.Setup(x => x.SaveValidationPackageFileAsync(It.IsAny<Package>(), It.IsAny<Stream>()))
299+
.Completes()
300+
.Verifiable();
301+
302+
var service = CreateService(symbolPackageService: symbolPackageService, symbolPackageFileService: symbolPackageFileService);
303+
var package = new Package() { PackageRegistration = new PackageRegistration() { Id = "theId" }, Version = "1.0.23" };
304+
package.SymbolPackages.Add(new SymbolPackage()
305+
{
306+
StatusKey = PackageStatus.FailedValidation,
307+
Key = 1232,
308+
Package = package
309+
});
310+
311+
// Act
312+
var result = await service.CreateAndUploadSymbolsPackage(package, new MemoryStream());
313+
314+
// Assert
315+
Assert.NotNull(result);
316+
Assert.Equal(PackageCommitResult.Success, result);
317+
symbolPackageFileService.VerifyAll();
318+
}
319+
267320
[Fact]
268321
public async Task WillDeleteSavedFileAndThrowWhenDBWriteFails()
269322
{

0 commit comments

Comments
 (0)