/// <exception cref="System.Exception"/> public virtual void TestThreadDumpAndDeadlocks() { new TestTimedOutTestsListener.Deadlock(); string s = null; while (true) { s = TimedOutTestsListener.BuildDeadlockInfo(); if (s != null) { break; } Thread.Sleep(100); } Assert.Equal(3, CountStringOccurrences(s, "BLOCKED")); Failure failure = new Failure(null, new Exception(TimedOutTestsListener.TestTimedOutPrefix )); StringWriter writer = new StringWriter(); new TimedOutTestsListener(new PrintWriter(writer)).TestFailure(failure); string @out = writer.ToString(); Assert.True(@out.Contains("THREAD DUMP")); Assert.True(@out.Contains("DEADLOCKS DETECTED")); System.Console.Out.WriteLine(@out); }
/// <exception cref="TimeoutException"/> /// <exception cref="System.Exception"/> public static void WaitFor(Supplier <bool> check, int checkEveryMillis, int waitForMillis ) { long st = Time.Now(); do { bool result = check.Get(); if (result) { return; } Thread.Sleep(checkEveryMillis); }while (Time.Now() - st < waitForMillis); throw new TimeoutException("Timed out waiting for condition. " + "Thread diagnostics:\n" + TimedOutTestsListener.BuildThreadDiagnosticString()); }