public async Task CancellationTokenChecks() { var clusterNotifierMock = new Mock <ClusterNotifier>(); clusterNotifierMock.Setup(i => i.DistributeToCluster(It.IsAny <InflightMessage>(), It.IsAny <CancellationToken>(), It.IsAny <string>())).Returns(Task.CompletedTask).Verifiable(); var context = MockStatefulServiceContextFactory.Default; var stateManager = new MockReliableStateManager(); var service = new BullfrogNotificationBackendService.BullfrogNotificationBackendService(context, stateManager, clusterNotifierMock.Object) { WaitTimeBetweenLoop = TimeSpan.FromMilliseconds(10) }; await service.IngestMessage(JsonMessage.ToString(), JsonMessage); var ctxSource = new CancellationTokenSource(); var T = service.InvokeRunAsync(ctxSource.Token); T.Wait(TimeSpan.FromMilliseconds(30)); ctxSource.Cancel(); Thread.Sleep(TimeSpan.FromSeconds(2)); //TODO: maybe rewrite T.IsCanceled.Should().BeTrue(); }
public async Task MessageDequeued_NotifierCalled() { var clusterNotifierMock = new Mock <ClusterNotifier>(); clusterNotifierMock.Setup(i => i.DistributeToCluster(It.IsAny <InflightMessage>(), It.IsAny <CancellationToken>(), It.IsAny <string>())).Returns(Task.CompletedTask).Verifiable(); var context = MockStatefulServiceContextFactory.Default; var stateManager = new MockReliableStateManager(); var service = new BullfrogNotificationBackendService.BullfrogNotificationBackendService(context, stateManager, clusterNotifierMock.Object) { WaitTimeBetweenLoop = TimeSpan.FromMilliseconds(10) }; await service.IngestMessage(JsonMessage.ToString(), JsonMessage); var ctxToken = new CancellationToken(); var T = service.InvokeRunAsync(ctxToken); T.Wait(TimeSpan.FromMilliseconds(30)); var queue = await stateManager.TryGetAsync <IReliableConcurrentQueue <InflightMessage> >(BullfrogNotificationBackendService.BullfrogNotificationBackendService.QueueName); var message = (await queue.Value.TryDequeueAsync(new MockTransaction(stateManager, 1), ctxToken)).Value; message.Should().BeNull(); clusterNotifierMock.VerifyAll(); }