public void TestTimeout_SoftTimeoutIsNull_NeverTimeout() { var timeout = TimeSpan.FromMilliseconds(20); using (var waitHandle = new ManualResetEventSlim()) using (var target = new RpcApplicationContext(null, timeout)) { RpcApplicationContext.SetCurrent(target); target.StartTimeoutWatch(); Assert.That(waitHandle.Wait(TimeSpan.FromMilliseconds(timeout.TotalMilliseconds * 2)), Is.False); Assert.That(RpcApplicationContext.IsCanceled, Is.False); } }
public void TestHardTimeout_Stopped_Never() { var timeout = TimeSpan.FromMilliseconds(20); using (var waitHandle = new ManualResetEventSlim()) using (var target = new RpcApplicationContext(timeout, timeout)) { RpcApplicationContext.SetCurrent(target); target.StartTimeoutWatch(); target.CancellationToken.Register(() => waitHandle.Set()); Assert.That(waitHandle.Wait(TimeSpan.FromSeconds(1))); target.StopTimeoutWatch(); Thread.Sleep(TimeSpan.FromMilliseconds(timeout.TotalMilliseconds * 2)); Assert.That(RpcApplicationContext.IsCanceled); } }
public void TestHardTimeout_TokenCanceledAndIsCanceledToBeTrue() { var timeout = TimeSpan.FromMilliseconds(20); using (var target = new RpcApplicationContext(timeout, timeout)) { RpcApplicationContext.SetCurrent(target); target.StartTimeoutWatch(); try { Thread.Sleep(TimeSpan.FromMilliseconds(timeout.TotalMilliseconds * 3)); Assert.Fail(); } catch (ThreadAbortException ex) { Assert.That(ex.ExceptionState, Is.EqualTo(RpcApplicationContext.HardTimeoutToken)); Thread.ResetAbort(); } Assert.That(RpcApplicationContext.IsCanceled); } }