コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
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);
        }
コード例 #4
0
        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());
            }
        }