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.223 by jsr166, Sat May 13 19:13:09 2017 UTC vs.
Revision 1.229 by jsr166, Sun May 14 03:15:37 2017 UTC

# Line 1063 | Line 1063 | public class JSR166TestCase extends Test
1063      }
1064  
1065      /**
1066 <     * Checks that thread does not terminate within the default
1067 <     * millisecond delay of {@code timeoutMillis()}.
1066 >     * Checks that thread eventually enters the expected blocked thread state.
1067       */
1068 <    void assertThreadStaysAlive(Thread thread) {
1069 <        assertThreadStaysAlive(thread, timeoutMillis());
1070 <    }
1071 <
1072 <    /**
1073 <     * Checks that thread does not terminate within the given millisecond delay.
1074 <     */
1075 <    void assertThreadStaysAlive(Thread thread, long millis) {
1076 <        try {
1077 <            // No need to optimize the failing case via Thread.join.
1078 <            delay(millis);
1079 <            assertTrue(thread.isAlive());
1080 <        } catch (InterruptedException fail) {
1082 <            threadFail("Unexpected InterruptedException");
1083 <        }
1084 <    }
1085 <
1086 <    /**
1087 <     * Checks that the threads do not terminate within the default
1088 <     * millisecond delay of {@code timeoutMillis()}.
1089 <     */
1090 <    void assertThreadsStayAlive(Thread... threads) {
1091 <        assertThreadsStayAlive(timeoutMillis(), threads);
1092 <    }
1093 <
1094 <    /**
1095 <     * Checks that the threads do not terminate within the given millisecond delay.
1096 <     */
1097 <    void assertThreadsStayAlive(long millis, Thread... threads) {
1098 <        try {
1099 <            // No need to optimize the failing case via Thread.join.
1100 <            delay(millis);
1101 <            for (Thread thread : threads)
1102 <                assertTrue(thread.isAlive());
1103 <        } catch (InterruptedException fail) {
1104 <            threadFail("Unexpected InterruptedException");
1068 >    void assertThreadBlocks(Thread thread, Thread.State expected) {
1069 >        // always sleep at least 1 ms, with high probability avoiding
1070 >        // transitory states
1071 >        for (long retries = LONG_DELAY_MS * 3 / 4; retries-->0; ) {
1072 >            try { delay(1); }
1073 >            catch (InterruptedException fail) {
1074 >                fail("Unexpected InterruptedException");
1075 >            }
1076 >            Thread.State s = thread.getState();
1077 >            if (s == expected)
1078 >                return;
1079 >            else if (s == Thread.State.TERMINATED)
1080 >                fail("Unexpected thread termination");
1081          }
1082 +        fail("timed out waiting for thread to enter thread state " + expected);
1083      }
1084  
1085      /**
# Line 1615 | Line 1592 | public class JSR166TestCase extends Test
1592          } catch (Throwable fail) {
1593              threadUnexpectedException(fail);
1594          }
1595 +    }
1596 +
1597 +    public void await(CyclicBarrier barrier) {
1598 +        try {
1599 +            barrier.await(LONG_DELAY_MS, MILLISECONDS);
1600 +        } catch (Throwable fail) {
1601 +            threadUnexpectedException(fail);
1602 +        }
1603      }
1604  
1605   //     /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines