657 |
|
public static long MEDIUM_DELAY_MS; |
658 |
|
public static long LONG_DELAY_MS; |
659 |
|
|
660 |
+ |
/** |
661 |
+ |
* A delay significantly longer than LONG_DELAY_MS. |
662 |
+ |
* Use this in a thread that is waited for via awaitTermination(Thread). |
663 |
+ |
*/ |
664 |
+ |
public static long LONGER_DELAY_MS; |
665 |
+ |
|
666 |
|
private static final long RANDOM_TIMEOUT; |
667 |
|
private static final long RANDOM_EXPIRED_TIMEOUT; |
668 |
|
private static final TimeUnit RANDOM_TIMEUNIT; |
722 |
|
SMALL_DELAY_MS = SHORT_DELAY_MS * 5; |
723 |
|
MEDIUM_DELAY_MS = SHORT_DELAY_MS * 10; |
724 |
|
LONG_DELAY_MS = SHORT_DELAY_MS * 200; |
725 |
+ |
LONGER_DELAY_MS = 2 * LONG_DELAY_MS; |
726 |
|
} |
727 |
|
|
728 |
|
private static final long TIMEOUT_DELAY_MS |
761 |
|
*/ |
762 |
|
public void threadRecordFailure(Throwable t) { |
763 |
|
System.err.println(t); |
764 |
< |
dumpTestThreads(); |
765 |
< |
threadFailure.compareAndSet(null, t); |
764 |
> |
if (threadFailure.compareAndSet(null, t)) |
765 |
> |
dumpTestThreads(); |
766 |
|
} |
767 |
|
|
768 |
|
public void setUp() { |
1108 |
|
&& (lockName = info.getLockName()) != null |
1109 |
|
&& lockName.startsWith("java.lang.ref.Reference$Lock")) |
1110 |
|
continue; |
1111 |
< |
if ("Finalizer".equals(name) |
1111 |
> |
if (("Finalizer".equals(name) || "Common-Cleaner".equals(name)) |
1112 |
|
&& (lockName = info.getLockName()) != null |
1113 |
< |
&& lockName.startsWith("java.lang.ref.ReferenceQueue$Lock")) |
1113 |
> |
&& lockName.startsWith("java.lang.ref")) |
1114 |
|
continue; |
1115 |
|
if ("checkForWedgedTest".equals(name)) |
1116 |
|
continue; |
1410 |
|
return NANOSECONDS.toMillis(System.nanoTime() - startNanoTime); |
1411 |
|
} |
1412 |
|
|
1406 |
– |
// void assertTerminatesPromptly(long timeoutMillis, Runnable r) { |
1407 |
– |
// long startTime = System.nanoTime(); |
1408 |
– |
// try { |
1409 |
– |
// r.run(); |
1410 |
– |
// } catch (Throwable fail) { threadUnexpectedException(fail); } |
1411 |
– |
// if (millisElapsedSince(startTime) > timeoutMillis/2) |
1412 |
– |
// throw new AssertionError("did not return promptly"); |
1413 |
– |
// } |
1414 |
– |
|
1415 |
– |
// void assertTerminatesPromptly(Runnable r) { |
1416 |
– |
// assertTerminatesPromptly(LONG_DELAY_MS/2, r); |
1417 |
– |
// } |
1418 |
– |
|
1413 |
|
/** |
1414 |
|
* Checks that timed f.get() returns the expected value, and does not |
1415 |
|
* wait for the timeout to elapse before returning. |
1444 |
|
* to terminate (using {@link Thread#join(long)}), else interrupts |
1445 |
|
* the thread (in the hope that it may terminate later) and fails. |
1446 |
|
*/ |
1447 |
< |
void awaitTermination(Thread t, long timeoutMillis) { |
1447 |
> |
void awaitTermination(Thread thread, long timeoutMillis) { |
1448 |
|
try { |
1449 |
< |
t.join(timeoutMillis); |
1449 |
> |
thread.join(timeoutMillis); |
1450 |
|
} catch (InterruptedException fail) { |
1451 |
|
threadUnexpectedException(fail); |
1452 |
|
} |
1453 |
< |
Thread.State state; |
1454 |
< |
if ((state = t.getState()) != Thread.State.TERMINATED) { |
1455 |
< |
t.interrupt(); |
1456 |
< |
threadFail("timed out waiting for thread to terminate; " |
1457 |
< |
+ "state=" + state); |
1453 |
> |
if (thread.getState() != Thread.State.TERMINATED) { |
1454 |
> |
String detail = String.format( |
1455 |
> |
"timed out waiting for thread to terminate, thread=%s, state=%s" , |
1456 |
> |
thread, thread.getState()); |
1457 |
> |
try { |
1458 |
> |
threadFail(detail); |
1459 |
> |
} finally { |
1460 |
> |
// Interrupt thread __after__ having reported its stack trace |
1461 |
> |
thread.interrupt(); |
1462 |
> |
} |
1463 |
|
} |
1464 |
|
} |
1465 |
|
|