public async Task SetResult_BeforeAwait_CompletesSuccessfully() { var ara = new AutoResetAwaitable <int>(); ara.SetResult(42); Assert.Equal(42, await ara); }
public async Task SetException_BeforeAwait_ThrowsAppropriateError() { var ara = new AutoResetAwaitable <int>(); ara.SetException(new FormatException()); await Assert.ThrowsAsync <FormatException>(async() => await ara); }
public async Task edge_case_cancel_after_delay_before_retry() { var waiter = new ManualResetEventSlim(false); var backoffAwaiter = new AutoResetAwaitable(); var backoffCalculated = false; var listener = Structure.Start( new SimpleProperties(), TestOptions( next => env => env.Response(500), op => { var existingBackoff = op.HttpBackoff; op.HttpBackoff = (options, existing) => { backoffAwaiter.Signal(); waiter.Wait(); backoffCalculated = true; return(existingBackoff(options, existing)); }; })); ConsulKvSimulator.PutKey("test", "1"); await backoffAwaiter.WaitOne(); // first request stopping var stopper = listener.Stop(); //stopper.Start(); waiter.Set(); await stopper; backoffCalculated.ShouldBeTrue(); }
public async Task SetCanceled_BeforeAwait_ThrowsAppropriateError(bool canceledToken) { var ara = new AutoResetAwaitable <int>(); var cts = new CancellationTokenSource(); if (canceledToken) { cts.Cancel(); } ara.SetCanceled(cts.Token); await Assert.ThrowsAsync <OperationCanceledException>(async() => await ara); }