Пример #1
0
        public async Task Add_ShallAddJob()
        {
            var inferenceRequest = new InferenceRequest();

            inferenceRequest.JobId         = Guid.NewGuid().ToString();
            inferenceRequest.PayloadId     = Guid.NewGuid().ToString();
            inferenceRequest.TransactionId = Guid.NewGuid().ToString();

            var store = new InferenceRequestRepository(_logger.Object, _jobsApi.Object, _inferenceRequestRepository.Object);
            await store.Add(inferenceRequest);

            _inferenceRequestRepository.Verify(p => p.AddAsync(It.IsAny <InferenceRequest>(), It.IsAny <CancellationToken>()), Times.Once());
            _inferenceRequestRepository.Verify(p => p.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once());
            _logger.VerifyLoggingMessageBeginsWith($"Inference request saved.", LogLevel.Debug, Times.Once());
        }
Пример #2
0
        public async Task Add_ShallRetryOnFailure()
        {
            _inferenceRequestRepository.Setup(p => p.AddAsync(It.IsAny <InferenceRequest>(), It.IsAny <CancellationToken>()))
            .Throws(new Exception("error"));

            var inferenceRequest = new InferenceRequest();

            inferenceRequest.JobId         = Guid.NewGuid().ToString();
            inferenceRequest.PayloadId     = Guid.NewGuid().ToString();
            inferenceRequest.TransactionId = Guid.NewGuid().ToString();

            var store = new InferenceRequestRepository(_logger.Object, _jobsApi.Object, _inferenceRequestRepository.Object);

            await Assert.ThrowsAsync <Exception>(async() => await store.Add(inferenceRequest));

            _logger.VerifyLoggingMessageBeginsWith($"Error saving inference request", LogLevel.Error, Times.Exactly(3));
            _inferenceRequestRepository.Verify(p => p.AddAsync(It.IsAny <InferenceRequest>(), It.IsAny <CancellationToken>()), Times.AtLeast(3));
        }