public void FabricClientRetryPolicy_3_OperationShouldTimeout() { SecurityCredentials sc = new NoneSecurityCredentials(); string[] ep = new string[] { "tcp://tempuri.org" }; FabricClientRetryPolicy rp = new FabricClientRetryPolicy(sc, ep, 5, new FixedWaitingPolicy(TimeSpan.FromMilliseconds(10)), AllErrorsTransientDetectionStrategy.Instance); Stopwatch sp = Stopwatch.StartNew(); bool operationCanceled = false; int attempts = 0; try { rp.ExecuteWithRetriesAsync((ct) => Task.Run(async() => { attempts++; await Task.Delay(Timeout.Infinite, ct); }), TimeSpan.FromMilliseconds(50), CancellationToken.None).GetAwaiter().GetResult(); } catch (TimeoutException) { Assert.IsTrue(sp.Elapsed < TimeSpan.FromSeconds(5), sp.Elapsed.ToString()); operationCanceled = true; } Assert.IsNotNull(rp.Client); Assert.AreEqual(5, attempts); Assert.AreEqual(true, operationCanceled); }
public void FabricClientRetryPolicyClientRetryShouldBeCancelled() { FabricClientRetryPolicy rp = new FabricClientRetryPolicy(5, FixedWaitingPolicy.Default, AllErrorsTransientDetectionStrategy.Instance); Stopwatch sp = Stopwatch.StartNew(); bool operationCanceled = false; int attempts = 0; FabricClient.QueryClient qc = null; try { // Force the object to be disposed. rp.Client.Dispose(); using (CancellationTokenSource cts = new CancellationTokenSource(50)) { rp.ExecuteWithRetriesAsync((ct) => Task.Run(async() => { attempts++; qc = rp.Client.QueryManager; await Task.Delay(Timeout.Infinite, ct); }), TimeSpan.Zero, cts.Token).GetAwaiter().GetResult(); } } catch (OperationCanceledException) { Assert.IsTrue(sp.Elapsed < TimeSpan.FromSeconds(5), sp.Elapsed.ToString()); operationCanceled = true; } Assert.IsNotNull(rp.Client); Assert.IsNotNull(qc); Assert.AreEqual(1, attempts); Assert.AreEqual(true, operationCanceled); }
public void FabricClientRetryPolicy_2_ShouldBeCancelled() { FabricClientSettings fcs = new FabricClientSettings() { ConnectionInitializationTimeout = TimeSpan.FromSeconds(5) }; FabricClientRetryPolicy rp = new FabricClientRetryPolicy(fcs, 5, FixedWaitingPolicy.Default, AllErrorsTransientDetectionStrategy.Instance); Stopwatch sp = Stopwatch.StartNew(); bool operationCanceled = false; int attempts = 0; try { using (CancellationTokenSource cts = new CancellationTokenSource(50)) { rp.ExecuteWithRetriesAsync((ct) => Task.Run(async() => { attempts++; await Task.Delay(Timeout.Infinite, ct); }), TimeSpan.Zero, cts.Token).GetAwaiter().GetResult(); } } catch (OperationCanceledException) { Assert.IsTrue(sp.Elapsed < TimeSpan.FromSeconds(5), sp.Elapsed.ToString()); operationCanceled = true; } Assert.IsNotNull(rp.Client); Assert.AreEqual(1, attempts); Assert.AreEqual(true, operationCanceled); }