Пример #1
0
        public async Task Take_ShallThrowWhenCancelled()
        {
            var cancellationSource = new CancellationTokenSource();

            _inferenceRequestRepository.Setup(p => p.FirstOrDefault(It.IsAny <Func <InferenceRequest, bool> >()))
            .Returns(default(InferenceRequest));

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

            cancellationSource.CancelAfter(100);
            await Assert.ThrowsAsync <OperationCanceledException>(async() => await store.Take(cancellationSource.Token));
        }
Пример #2
0
        public async Task Take_ShallReturnQueuedItem()
        {
            var inferenceRequest = new InferenceRequest();

            inferenceRequest.JobId         = Guid.NewGuid().ToString();
            inferenceRequest.PayloadId     = Guid.NewGuid().ToString();
            inferenceRequest.TransactionId = Guid.NewGuid().ToString();
            var cancellationSource = new CancellationTokenSource();

            _inferenceRequestRepository.SetupSequence(p => p.FirstOrDefault(It.IsAny <Func <InferenceRequest, bool> >()))
            .Returns(inferenceRequest);

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

            var result = await store.Take(cancellationSource.Token);

            Assert.Equal(result.JobId, inferenceRequest.JobId);
            _logger.VerifyLogging($"Updating request {inferenceRequest.JobId} to InProgress.", LogLevel.Debug, Times.AtLeastOnce());
        }