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.144 by jsr166, Mon Sep 14 03:14:01 2015 UTC vs.
Revision 1.146 by jsr166, Fri Sep 25 23:32:15 2015 UTC

# Line 40 | Line 40 | import java.util.concurrent.CyclicBarrie
40   import java.util.concurrent.ExecutionException;
41   import java.util.concurrent.Executors;
42   import java.util.concurrent.ExecutorService;
43 + import java.util.concurrent.ForkJoinPool;
44   import java.util.concurrent.Future;
45   import java.util.concurrent.RecursiveAction;
46   import java.util.concurrent.RecursiveTask;
# Line 198 | Line 199 | public class JSR166TestCase extends Test
199      }
200  
201      protected void runTestProfiled() throws Throwable {
202 <        // Warmup run, notably to trigger all needed classloading.
203 <        super.runTest();
203 <        long t0 = System.nanoTime();
204 <        try {
202 >        for (int i = 0; i < 2; i++) {
203 >            long startTime = System.nanoTime();
204              super.runTest();
205 <        } finally {
206 <            long elapsedMillis = millisElapsedSince(t0);
207 <            if (elapsedMillis >= profileThreshold)
205 >            long elapsedMillis = millisElapsedSince(startTime);
206 >            if (elapsedMillis < profileThreshold)
207 >                break;
208 >            // Never report first run of any test; treat it as a
209 >            // warmup run, notably to trigger all needed classloading,
210 >            if (i > 0)
211                  System.out.printf("%n%s: %d%n", toString(), elapsedMillis);
212          }
213      }
# Line 520 | Line 522 | public class JSR166TestCase extends Test
522          setDelays();
523      }
524  
525 +    void tearDownFail(String format, Object... args) {
526 +        String msg = toString() + ": " + String.format(format, args);
527 +        System.err.println(msg);
528 +        printAllStackTraces();
529 +        throw new AssertionFailedError(msg);
530 +    }
531 +
532      /**
533       * Extra checks that get done for all test cases.
534       *
# Line 547 | Line 556 | public class JSR166TestCase extends Test
556          }
557  
558          if (Thread.interrupted())
559 <            throw new AssertionFailedError("interrupt status set in main thread");
559 >            tearDownFail("interrupt status set in main thread");
560  
561          checkForkJoinPoolThreadLeaks();
562      }
# Line 556 | Line 565 | public class JSR166TestCase extends Test
565       * Finds missing try { ... } finally { joinPool(e); }
566       */
567      void checkForkJoinPoolThreadLeaks() throws InterruptedException {
568 <        Thread[] survivors = new Thread[5];
568 >        Thread[] survivors = new Thread[7];
569          int count = Thread.enumerate(survivors);
570          for (int i = 0; i < count; i++) {
571              Thread thread = survivors[i];
# Line 564 | Line 573 | public class JSR166TestCase extends Test
573              if (name.startsWith("ForkJoinPool-")) {
574                  // give thread some time to terminate
575                  thread.join(LONG_DELAY_MS);
576 <                if (!thread.isAlive()) continue;
577 <                throw new AssertionFailedError
578 <                    (String.format("Found leaked ForkJoinPool thread test=%s thread=%s%n",
570 <                                   toString(), name));
576 >                if (thread.isAlive())
577 >                    tearDownFail("Found leaked ForkJoinPool thread thread=%s",
578 >                                 thread);
579              }
580          }
581 +
582 +        if (!ForkJoinPool.commonPool()
583 +            .awaitQuiescence(LONG_DELAY_MS, MILLISECONDS))
584 +            tearDownFail("ForkJoin common pool thread stuck");
585      }
586  
587      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines