public async Task DoesNotReEnqueueProcessingIfValidationSetTimesOut()
        {
            const int postponeMinutes = 1;

            AddValidation("validation1", ValidationStatus.Incomplete);

            Configuration.TimeoutValidationSetAfter      = TimeSpan.FromDays(1);
            Configuration.ValidationMessageRecheckPeriod = TimeSpan.FromMinutes(postponeMinutes);

            ValidationSet.Created = DateTime.UtcNow - TimeSpan.FromDays(1) - TimeSpan.FromHours(1);

            ValidationStorageServiceMock
            .Setup(s => s.UpdateValidationSetAsync(It.IsAny <PackageValidationSet>()))
            .Callback <PackageValidationSet>(s => s.Updated = DateTime.UtcNow)
            .Returns(Task.FromResult(0));

            var processor = CreateProcessor();
            await processor.ProcessValidationOutcomeAsync(ValidationSet, PackageValidatingEntity, ProcessorStats);

            TelemetryServiceMock
            .Verify(t => t.TrackValidationSetTimeout(Package.PackageRegistration.Id, Package.NormalizedVersion, ValidationSet.ValidationTrackingId));
            ValidationEnqueuerMock
            .Verify(ve => ve.StartValidationAsync(It.IsAny <PackageValidationMessageData>(), It.IsAny <DateTimeOffset>()), Times.Never);
            PackageFileServiceMock
            .Verify(x => x.DeletePackageForValidationSetAsync(It.IsAny <PackageValidationSet>()), Times.Never);
        }
Esempio n. 2
0
        private List <string> RecordOperationOrder()
        {
            var operations = new List <string>();

            PackageStateProcessorMock
            .Setup(x => x.SetStatusAsync(It.IsAny <IValidatingEntity <Package> >(), It.IsAny <PackageValidationSet>(), It.IsAny <PackageStatus>()))
            .Returns(Task.CompletedTask)
            .Callback(() => operations.Add(nameof(IStatusProcessor <Package> .SetStatusAsync)));
            ValidationStorageServiceMock
            .Setup(x => x.UpdateValidationSetAsync(It.IsAny <PackageValidationSet>()))
            .Returns(Task.CompletedTask)
            .Callback(() => operations.Add(nameof(IValidationStorageService.UpdateValidationSetAsync)));
            MessageServiceMock
            .Setup(x => x.SendPublishedMessageAsync(It.IsAny <Package>()))
            .Returns(Task.CompletedTask)
            .Callback(() => operations.Add(nameof(IMessageService <Package> .SendPublishedMessageAsync)));
            MessageServiceMock
            .Setup(x => x.SendValidationFailedMessageAsync(It.IsAny <Package>(), It.IsAny <PackageValidationSet>()))
            .Returns(Task.CompletedTask)
            .Callback(() => operations.Add(nameof(IMessageService <Package> .SendValidationFailedMessageAsync)));
            TelemetryServiceMock
            .Setup(x => x.TrackTotalValidationDuration(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <TimeSpan>(), It.IsAny <bool>()))
            .Callback(() => operations.Add(nameof(ITelemetryService.TrackTotalValidationDuration)));
            PackageFileServiceMock
            .Setup(x => x.DeletePackageForValidationSetAsync(It.IsAny <PackageValidationSet>()))
            .Returns(Task.CompletedTask)
            .Callback(() => operations.Add(nameof(IValidationFileService.DeletePackageForValidationSetAsync)));
            return(operations);
        }
        public async Task DoesNotSendValidatingTooLongMessageOnRevalidations()
        {
            const int postponeMinutes = 1;

            AddValidation("validation1", ValidationStatus.Incomplete);

            Configuration.TimeoutValidationSetAfter        = TimeSpan.FromDays(1);
            Configuration.ValidationSetNotificationTimeout = TimeSpan.FromMinutes(20);
            Configuration.ValidationMessageRecheckPeriod   = TimeSpan.FromMinutes(postponeMinutes);

            ValidationSet.Created = DateTime.UtcNow - TimeSpan.FromMinutes(21);
            ValidationSet.Updated = DateTime.UtcNow - TimeSpan.FromMinutes(15);

            ValidationStorageServiceMock
            .Setup(s => s.UpdateValidationSetAsync(It.IsAny <PackageValidationSet>()))
            .Callback <PackageValidationSet>(s => s.Updated = DateTime.UtcNow)
            .Returns(Task.FromResult(0));

            ValidationStorageServiceMock
            .Setup(s => s.GetValidationSetCountAsync(PackageValidatingEntity))
            .Returns(Task.FromResult(2));

            // Process the outcome once - the "too long to validate" message should NOT be sent.
            var processor = CreateProcessor();
            await processor.ProcessValidationOutcomeAsync(ValidationSet, PackageValidatingEntity, ProcessorStats);

            TelemetryServiceMock
            .Verify(t => t.TrackSentValidationTakingTooLongMessage(Package.PackageRegistration.Id, Package.NormalizedVersion, ValidationSet.ValidationTrackingId), Times.Never);
            MessageServiceMock
            .Verify(m => m.SendValidationTakingTooLongMessageAsync(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);
        }
Esempio n. 4
0
        public async Task ReEnqueuesProcessingIfNotAllComplete()
        {
            const int postponeMinutes = 1;

            AddValidation("validation1", ValidationStatus.Incomplete);
            Configuration.ValidationMessageRecheckPeriod = TimeSpan.FromMinutes(postponeMinutes);
            Configuration.TimeoutValidationSetAfter      = TimeSpan.FromDays(1);

            PackageValidationMessageData messageData = null;
            DateTimeOffset postponeTill = DateTimeOffset.MinValue;

            ValidationEnqueuerMock
            .Setup(ve => ve.SendMessageAsync(It.IsAny <PackageValidationMessageData>(), It.IsAny <DateTimeOffset>()))
            .Returns(Task.FromResult(0))
            .Callback <PackageValidationMessageData, DateTimeOffset>((pv, pt) => {
                messageData  = pv;
                postponeTill = pt;
            });

            var processor = CreateProcessor();
            var startTime = DateTimeOffset.Now;
            await processor.ProcessValidationOutcomeAsync(ValidationSet, PackageValidatingEntity, ProcessorStats, ScheduleNextCheck);

            ValidationStorageServiceMock
            .Verify(s => s.UpdateValidationSetAsync(ValidationSet), Times.Once);

            ValidationEnqueuerMock
            .Verify(ve => ve.SendMessageAsync(It.IsAny <PackageValidationMessageData>(), It.IsAny <DateTimeOffset>()), Times.Once());

            PackageStateProcessorMock.Verify(
                x => x.SetStatusAsync(It.IsAny <PackageValidatingEntity>(), It.IsAny <PackageValidationSet>(), It.IsAny <PackageStatus>()),
                Times.Never);

            PackageFileServiceMock.Verify(
                x => x.DeletePackageForValidationSetAsync(It.IsAny <PackageValidationSet>()),
                Times.Never);

            Assert.NotNull(messageData);
            Assert.Equal(PackageValidationMessageType.ProcessValidationSet, messageData.Type);
            Assert.Equal(ValidationSet.ValidationTrackingId, messageData.ProcessValidationSet.ValidationTrackingId);
            Assert.Equal(ValidationSet.PackageId, messageData.ProcessValidationSet.PackageId);
            Assert.Equal(Package.NormalizedVersion, messageData.ProcessValidationSet.PackageVersion);
            Assert.Equal(ValidationSet.ValidatingType, messageData.ProcessValidationSet.ValidatingType);
            Assert.Equal(ValidationSet.PackageKey, messageData.ProcessValidationSet.EntityKey);
            Assert.Equal(postponeMinutes, (postponeTill - startTime).TotalMinutes, 0);
            Assert.Equal(ValidationSetStatus.InProgress, ValidationSet.ValidationSetStatus);
        }
        public async Task SendsTooLongNotificationOnlyWhenItConcernsRequiredValidation(
            ValidationStatus requiredValidationState,
            ValidationStatus optionalValidationState,
            bool requiredValidationSucceeded)
        {
            bool expectedNotification = requiredValidationState == ValidationStatus.Incomplete || requiredValidationState == ValidationStatus.NotStarted;

            AddValidation("requiredValidation", requiredValidationState, ValidationFailureBehavior.MustSucceed);
            AddValidation("optionalValidaiton", optionalValidationState, ValidationFailureBehavior.AllowedToFail);
            ProcessorStats.AnyRequiredValidationSucceeded  = requiredValidationSucceeded;
            Configuration.TimeoutValidationSetAfter        = TimeSpan.FromDays(1);
            Configuration.ValidationSetNotificationTimeout = TimeSpan.FromMinutes(20);
            Configuration.ValidationMessageRecheckPeriod   = TimeSpan.FromMinutes(1);

            ValidationSet.Created = DateTime.UtcNow - Configuration.ValidationSetNotificationTimeout - TimeSpan.FromMinutes(1);
            ValidationSet.Updated = DateTime.UtcNow - TimeSpan.FromMinutes(15);

            ValidationStorageServiceMock
            .Setup(s => s.UpdateValidationSetAsync(It.IsAny <PackageValidationSet>()))
            .Callback <PackageValidationSet>(s => s.Updated = DateTime.UtcNow)
            .Returns(Task.CompletedTask);

            ValidationStorageServiceMock
            .Setup(s => s.GetValidationSetCountAsync(PackageValidatingEntity))
            .Returns(Task.FromResult(1));

            var processor = CreateProcessor();
            await processor.ProcessValidationOutcomeAsync(ValidationSet, PackageValidatingEntity, ProcessorStats);

            if (expectedNotification)
            {
                MessageServiceMock
                .Verify(m => m.SendValidationTakingTooLongMessageAsync(Package), Times.Once());
            }
            else
            {
                MessageServiceMock
                .Verify(m => m.SendValidationTakingTooLongMessageAsync(Package), Times.Never());
            }
        }