There's a lot of prior art in JSR166TestCase.java. In general, junit/testng don't have support for test methods that need to run code in more than one thread, and jsr166 tck tests do that a lot.
Often you want a higher-level blocking API like: public void await(CountDownLatch latch, long timeoutMillis) { boolean timedOut = false; try { timedOut = !latch.await(timeoutMillis, MILLISECONDS); } catch (Throwable fail) { threadUnexpectedException(fail); } if (timedOut) fail("timed out waiting for CountDownLatch for " + (timeoutMillis/1000) + " sec"); } public void await(CountDownLatch latch) { await(latch, LONG_DELAY_MS); } On Thu, Jan 9, 2020 at 5:47 AM Julia Boes <julia.b...@oracle.com> wrote: > Hi, > > This test-only RFR proposes a tool for timeout testing for the JDK test > library. It runs a task in a separate thread and cancels the task if it > doesn't complete within a given timeout. Any exception thrown by the > task is propagated transparently. > > TestNG doesn't currently provide this functionality but it seems like a > handy little tool to have. The webrev includes several sample use cases. > > Bug: https://bugs.openjdk.java.net/browse/JDK-8231710 > Webrev: http://cr.openjdk.java.net/~jboes/webrevs/8231710/webrev.01/ > > Any feedback appreciated. > > Regards, > Julia > > >