/// <summary> /// This test sets off a blocking thread and then interrupts it, before /// checking that the thread was interrupted /// </summary> /// <exception cref="System.Exception">any exception other than that which was expected /// </exception> public virtual void TestInterruptedWaitForProxy() { TestRPCWaitForProxy.RpcThread worker = new TestRPCWaitForProxy.RpcThread(this, 100 ); worker.Start(); Thread.Sleep(1000); Assert.True("worker hasn't started", worker.waitStarted); worker.Interrupt(); worker.Join(); Exception caught = worker.GetCaught(); NUnit.Framework.Assert.IsNotNull("No exception was raised", caught); // looking for the root cause here, which can be wrapped // as part of the NetUtils work. Having this test look // a the type of exception there would be brittle to improvements // in exception diagnostics. Exception cause = caught.InnerException; if (cause == null) { // no inner cause, use outer exception as root cause. cause = caught; } if (!(cause is ThreadInterruptedException) && !(cause is ClosedByInterruptException )) { throw caught; } }
/// <summary> /// This tests that the time-bounded wait for a proxy operation works, and /// times out. /// </summary> /// <exception cref="System.Exception">any exception other than that which was expected /// </exception> public virtual void TestWaitForProxy() { TestRPCWaitForProxy.RpcThread worker = new TestRPCWaitForProxy.RpcThread(this, 0); worker.Start(); worker.Join(); Exception caught = worker.GetCaught(); NUnit.Framework.Assert.IsNotNull("No exception was raised", caught); if (!(caught is ConnectException)) { throw caught; } }