ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/JSR166TestCase.java
(Generate patch)

Comparing jsr166/src/test/tck/JSR166TestCase.java (file contents):
Revision 1.254 by jsr166, Wed Apr 24 17:36:09 2019 UTC vs.
Revision 1.257 by jsr166, Wed Aug 14 23:06:11 2019 UTC

# Line 288 | Line 288 | public class JSR166TestCase extends Test
288              // Avoid spurious reports with enormous runsPerTest.
289              // A single test case run should never take more than 1 second.
290              // But let's cap it at the high end too ...
291 <            final int timeoutMinutes =
292 <                Math.min(15, Math.max(runsPerTest / 60, 1));
291 >            final int timeoutMinutesMin = Math.max(runsPerTest / 60, 1)
292 >                * Math.max((int) delayFactor, 1);
293 >            final int timeoutMinutes = Math.min(15, timeoutMinutesMin);
294              for (TestCase lastTestCase = currentTestCase;;) {
295                  try { MINUTES.sleep(timeoutMinutes); }
296                  catch (InterruptedException unexpected) { break; }
# Line 684 | Line 685 | public class JSR166TestCase extends Test
685      static TimeUnit randomTimeUnit() { return RANDOM_TIMEUNIT; }
686  
687      /**
688 +     * Returns a random boolean; a "coin flip".
689 +     */
690 +    static boolean randomBoolean() {
691 +        return ThreadLocalRandom.current().nextBoolean();
692 +    }
693 +
694 +    /**
695 +     * Returns a random element from given choices.
696 +     */
697 +    <T> T chooseRandomly(T... choices) {
698 +        return choices[ThreadLocalRandom.current().nextInt(choices.length)];
699 +    }
700 +
701 +    /**
702       * Returns the shortest timed delay. This can be scaled up for
703       * slow machines using the jsr166.delay.factor system property,
704       * or via jtreg's -timeoutFactor: flag.
# Line 1366 | Line 1381 | public class JSR166TestCase extends Test
1381      }
1382  
1383      /**
1384 +     * Spin-waits up to LONG_DELAY_MS milliseconds for the current thread to
1385 +     * be interrupted.  Clears the interrupt status before returning.
1386 +     */
1387 +    void awaitInterrupted() {
1388 +        for (long startTime = 0L; !Thread.interrupted(); ) {
1389 +            if (startTime == 0L)
1390 +                startTime = System.nanoTime();
1391 +            else if (millisElapsedSince(startTime) > LONG_DELAY_MS)
1392 +                fail("timed out waiting for thread interrupt");
1393 +            Thread.yield();
1394 +        }
1395 +    }
1396 +
1397 +    /**
1398       * Returns the number of milliseconds since time given by
1399       * startNanoTime, which must have been previously returned from a
1400       * call to {@link System#nanoTime()}.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines