Example #1
0
        public async Task TransitionState_Fail_ShallPutJobInFaultedState()
        {
            var job = new InferenceJob();

            job.JobId     = Guid.NewGuid().ToString();
            job.PayloadId = Guid.NewGuid().ToString();
            job.SetStoragePath("/path/to/job");
            job.State    = InferenceJobState.Creating;
            job.TryCount = 3;

            var cancellationSource = new CancellationTokenSource();

            _inferenceJobRepository.SetupSequence(p => p.AsQueryable())
            .Returns((new List <InferenceJob>()
            {
                job
            }).AsQueryable());
            _inferenceJobRepository.Setup(p => p.SaveChangesAsync(It.IsAny <CancellationToken>()));
            var jobStore = new ClaraJobRepository(
                _logger.Object,
                _configuration,
                _fileSystem,
                _inferenceJobRepository.Object);

            var result = await jobStore.TransitionState(job, InferenceJobStatus.Fail, cancellationSource.Token);

            Assert.Equal(job, result);
            Assert.Equal(InferenceJobState.Faulted, result.State);
            Assert.Equal(4, result.TryCount);
            _logger.VerifyLoggingMessageBeginsWith($"Job {job.JobId} exceeded maximum number of retries.", LogLevel.Warning, Times.Once());
            _inferenceJobRepository.Verify(p => p.SaveChangesAsync(cancellationSource.Token), Times.Once());
        }
Example #2
0
        public async Task TransitionState_Fail_ShallTransitionJob(InferenceJobState initalState, InferenceJobState endingState)
        {
            var job = new InferenceJob();

            job.JobId     = Guid.NewGuid().ToString();
            job.PayloadId = Guid.NewGuid().ToString();
            job.SetStoragePath("/path/to/job");
            job.State    = initalState;
            job.TryCount = 1;

            var cancellationSource = new CancellationTokenSource();

            _inferenceJobRepository.SetupSequence(p => p.AsQueryable())
            .Returns((new List <InferenceJob>()
            {
                job
            }).AsQueryable());
            _inferenceJobRepository.Setup(p => p.SaveChangesAsync(It.IsAny <CancellationToken>()));
            var jobStore = new ClaraJobRepository(
                _logger.Object,
                _configuration,
                _fileSystem,
                _inferenceJobRepository.Object);

            var result = await jobStore.TransitionState(job, InferenceJobStatus.Fail, cancellationSource.Token);

            Assert.Equal(job, result);
            Assert.Equal(endingState, endingState);
            Assert.Equal(2, result.TryCount);
            _logger.VerifyLoggingMessageBeginsWith($"Putting inference job {job.JobId} back to {endingState} state for retry.", LogLevel.Information, Times.Once());
            _inferenceJobRepository.Verify(p => p.SaveChangesAsync(cancellationSource.Token), Times.Once());
        }