public void RunAsyncCancellation() { Console.WriteLine("StatefulServiceLifeCycleTests - Test Method: RunAsyncCancellation()"); var serviceContext = TestMocksRepository.GetMockStatefulServiceContext(); var testService = new RunAsyncCancellationTestService(serviceContext); IStatefulServiceReplica testServiceReplica = new StatefulServiceReplicaAdapter(serviceContext, testService); var partition = new Mock <IStatefulServicePartition>(); partition.SetupGet(p => p.WriteStatus).Returns(PartitionAccessStatus.Granted); testServiceReplica.OpenAsync(ReplicaOpenMode.New, partition.Object, CancellationToken.None).GetAwaiter().GetResult(); Console.WriteLine(@"// U -> P"); testServiceReplica.ChangeRoleAsync(ReplicaRole.Primary, CancellationToken.None).GetAwaiter().GetResult(); CancellationTokenSource source = new CancellationTokenSource(10000); while (!testService.StartedWaiting) { Task.Delay(100, source.Token).GetAwaiter().GetResult(); } // This will throw if cancellation propagates out, as canceling of RunAsync is awaited during // change role away from primary. Console.WriteLine(@"// P -> S"); testServiceReplica.ChangeRoleAsync(ReplicaRole.ActiveSecondary, CancellationToken.None).GetAwaiter().GetResult(); partition.Verify(p => p.ReportFault(It.IsAny <FaultType>()), Times.Never()); }
public void RunAsyncCancellation() { Console.WriteLine("StatelessServiceLifeCycleTests - Test Method: RunAsyncCancellation()"); var serviceContext = TestMocksRepository.GetMockStatelessServiceContext(); var testService = new RunAsyncCancellationTestService(serviceContext); IStatelessServiceInstance testServiceReplica = new StatelessServiceInstanceAdapter(serviceContext, testService); var partition = new Mock <IStatelessServicePartition>(); testServiceReplica.OpenAsync(partition.Object, CancellationToken.None).GetAwaiter().GetResult(); CancellationTokenSource source = new CancellationTokenSource(10000); while (!testService.StartedWaiting) { Task.Delay(100, source.Token).GetAwaiter().GetResult(); } // This will throw if cancellation propagates out, as canceling of RunAsync is // awaited during close of stateless serice instance. testServiceReplica.CloseAsync(CancellationToken.None).GetAwaiter().GetResult(); partition.Verify(p => p.ReportFault(It.IsAny <FaultType>()), Times.Never()); }