Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
/ NuGet.Jobs Public archive

[Orchestrator] Only send 'package validating too long' email on initial validation #542

Merged
merged 1 commit into from
Aug 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ private async Task<TimeSpan> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,12 @@ public async Task DoesNotReEnqueueProcessingIfValidationSetTimesOut()
.Verify(x => x.DeletePackageForValidationSetAsync(It.IsAny<PackageValidationSet>()), 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;

Expand All @@ -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<PackageValidationSet>()))
.Callback<PackageValidationSet>(s => s.Updated = DateTime.UtcNow)
Expand All @@ -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<PackageValidationMessageData>(), It.IsAny<DateTimeOffset>()), Times.Once);
PackageFileServiceMock
.Verify(x => x.DeletePackageForValidationSetAsync(It.IsAny<PackageValidationSet>()), 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<PackageValidationMessageData>(), It.IsAny<DateTimeOffset>()), Times.Once);
PackageFileServiceMock
.Verify(x => x.DeletePackageForValidationSetAsync(It.IsAny<PackageValidationSet>()), 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<PackageValidationMessageData>(), It.IsAny<DateTimeOffset>()), Times.Once);
PackageFileServiceMock
.Verify(x => x.DeletePackageForValidationSetAsync(It.IsAny<PackageValidationSet>()), Times.Never);
}

TelemetryServiceMock.ResetCalls();
MessageServiceMock.ResetCalls();
Expand Down