diff --git a/src/NuGet.Services.Validation.Orchestrator/ValidationOutcomeProcessor.cs b/src/NuGet.Services.Validation.Orchestrator/ValidationOutcomeProcessor.cs index 851cb2c2a..99bc21b5d 100644 --- a/src/NuGet.Services.Validation.Orchestrator/ValidationOutcomeProcessor.cs +++ b/src/NuGet.Services.Validation.Orchestrator/ValidationOutcomeProcessor.cs @@ -221,6 +221,7 @@ private async Task UpdateValidationDurationAsync(PackageValidationSet // is greater than the configured threshold. Service Bus message duplication for a single validation // set will not cause multiple notices to be sent due to the row version on PackageValidationSet. if (tooLongNotificationAllowed && + validatingEntity.Status == PackageStatus.Validating && validationSetDuration > _validationConfiguration.ValidationSetNotificationTimeout && previousDuration <= _validationConfiguration.ValidationSetNotificationTimeout && await _validationStorageService.GetValidationSetCountAsync(validatingEntity) == 1) diff --git a/tests/NuGet.Services.Validation.Orchestrator.Tests/ValidationOutcomeProcessorFacts.cs b/tests/NuGet.Services.Validation.Orchestrator.Tests/ValidationOutcomeProcessorFacts.cs index eaeb5c7df..a6eaaba15 100644 --- a/tests/NuGet.Services.Validation.Orchestrator.Tests/ValidationOutcomeProcessorFacts.cs +++ b/tests/NuGet.Services.Validation.Orchestrator.Tests/ValidationOutcomeProcessorFacts.cs @@ -116,8 +116,12 @@ public async Task DoesNotReEnqueueProcessingIfValidationSetTimesOut() .Verify(x => x.DeletePackageForValidationSetAsync(It.IsAny()), Times.Never); } - [Fact] - public async Task SendsValidatingTooLongMessageOnce() + [Theory] + [InlineData(PackageStatus.Available, false)] + [InlineData(PackageStatus.Deleted, false)] + [InlineData(PackageStatus.Validating, true)] + [InlineData(PackageStatus.FailedValidation, false)] + public async Task SendsValidatingTooLongMessageOnlyIfPackageIsInValidatingState(PackageStatus packageStatus, bool shouldSend) { const int postponeMinutes = 1; @@ -130,6 +134,8 @@ public async Task SendsValidatingTooLongMessageOnce() ValidationSet.Created = DateTime.UtcNow - TimeSpan.FromMinutes(21); ValidationSet.Updated = DateTime.UtcNow - TimeSpan.FromMinutes(15); + PackageValidatingEntity.EntityRecord.PackageStatusKey = packageStatus; + ValidationStorageServiceMock .Setup(s => s.UpdateValidationSetAsync(It.IsAny())) .Callback(s => s.Updated = DateTime.UtcNow) @@ -143,14 +149,28 @@ public async Task SendsValidatingTooLongMessageOnce() var processor = CreateProcessor(); await processor.ProcessValidationOutcomeAsync(ValidationSet, PackageValidatingEntity, ProcessorStats); - TelemetryServiceMock - .Verify(t => t.TrackSentValidationTakingTooLongMessage(Package.PackageRegistration.Id, Package.NormalizedVersion, ValidationSet.ValidationTrackingId), Times.Once); - MessageServiceMock - .Verify(m => m.SendValidationTakingTooLongMessage(Package), Times.Once); - ValidationEnqueuerMock - .Verify(ve => ve.StartValidationAsync(It.IsAny(), It.IsAny()), Times.Once); - PackageFileServiceMock - .Verify(x => x.DeletePackageForValidationSetAsync(It.IsAny()), Times.Never); + if (shouldSend) + { + TelemetryServiceMock + .Verify(t => t.TrackSentValidationTakingTooLongMessage(Package.PackageRegistration.Id, Package.NormalizedVersion, ValidationSet.ValidationTrackingId), Times.Once); + MessageServiceMock + .Verify(m => m.SendValidationTakingTooLongMessage(Package), Times.Once); + ValidationEnqueuerMock + .Verify(ve => ve.StartValidationAsync(It.IsAny(), It.IsAny()), Times.Once); + PackageFileServiceMock + .Verify(x => x.DeletePackageForValidationSetAsync(It.IsAny()), Times.Never); + } + else + { + TelemetryServiceMock + .Verify(t => t.TrackSentValidationTakingTooLongMessage(Package.PackageRegistration.Id, Package.NormalizedVersion, ValidationSet.ValidationTrackingId), Times.Never); + MessageServiceMock + .Verify(m => m.SendValidationTakingTooLongMessage(Package), Times.Never); + ValidationEnqueuerMock + .Verify(ve => ve.StartValidationAsync(It.IsAny(), It.IsAny()), Times.Once); + PackageFileServiceMock + .Verify(x => x.DeletePackageForValidationSetAsync(It.IsAny()), Times.Never); + } TelemetryServiceMock.ResetCalls(); MessageServiceMock.ResetCalls();