summaryrefslogtreecommitdiff
path: root/jsr166-tests/src/test/java/jsr166/PhaserTest.java
diff options
context:
space:
mode:
authorTobias Thierer <tobiast@google.com>2017-02-19 15:01:51 +0000
committerTobias Thierer <tobiast@google.com>2017-02-19 17:13:51 +0000
commitcff661d65e3e6e2ac731ebbf938251656deb4be4 (patch)
treed7174a0609e9bf7124733e593555e5b96cf2427c /jsr166-tests/src/test/java/jsr166/PhaserTest.java
parentb2af2e6d63267a4ab475fd288e6a93e3a183b59b (diff)
Port JSR166 LinkedTransferQueueTest flakiness fix
This CL cherry-picks the following upstream (*) test changes ("upstream" here is JSR166's CVS repository cvs -d ':pserver:anonymous@gee.cs.oswego.edu/home/jsr166/jsr166' This is in contrast to the code under test, whose upstream is OpenJDK). ===== src/test/tck/LinkedTransferQueueTest.java revision 1.70 date: 2017/02/18 16:37:49; author: jsr166; state: Exp; lines: +11 -5 waitForThreadToEnterWaitState should fail on timeout; tests should tolerate transient blocking Thread.State at any time (e.g. due to classloading) src/test/tck/JSR166TestCase.java revision 1.219 date: 2017/02/18 16:37:49; author: jsr166; state: Exp; lines: +43 -3 waitForThreadToEnterWaitState should fail on timeout; tests should tolerate transient blocking Thread.State at any time (e.g. due to classloading) src/test/tck/PhaserTest.java revision 1.45 date: 2017/02/18 15:05:55; author: jsr166; state: Exp; lines: +10 -10 use default timeout of LONG_DELAY_MS with waitForThreadToEnterWaitState ====== The effect of this CL is to fix flakiness in LinkedTransferQueueTest's testTransfer2() and testWaitingConsumer(). These test methods need to wait until a background thread was blocked waiting on a LinkedTransferQueue; before this CL, they did so by calling a helper method that waited for the background thread's state to become WAITING, TIMED_WAITING, or BLOCKED. After this CL, they also check that the LinkedTransferQueue is in the expected state before they stop waiting. The additional check is necessary because LinkedTransferQueue uses LockSupport.park(), which on Android involves a synchronized lock and therefore BLOCKED state. This caused the test methods to prematurely stop waiting, which caused the test to fail. The concrete failure could also have been prevented by waiting for the thread to enter WAITING or TIMED_WAITING state rather than BLOCKED. This was considered but not chosen by upstream since it would still have made assumptions about those states not being entered elsewhere. This CL also changes the waiting logic to fail() the test upon timeout. PhaserTest was changed to use longer timeouts (10sec rather than 250msec) to avoid flaky timeout failures. Bug: 34814528 Test: LinkedTransferQueueTest Test: PhaserTest Test: Checked that testTransfer2() and testWaitingConsumer() are non-flaky by running their body 10,000 times each in a loop. Change-Id: I112ee1fba8aea6ca97ca0f99bba0fc9f00e5c0c2
Diffstat (limited to 'jsr166-tests/src/test/java/jsr166/PhaserTest.java')
-rw-r--r--jsr166-tests/src/test/java/jsr166/PhaserTest.java20
1 files changed, 10 insertions, 10 deletions
diff --git a/jsr166-tests/src/test/java/jsr166/PhaserTest.java b/jsr166-tests/src/test/java/jsr166/PhaserTest.java
index 673e556a10..121901776b 100644
--- a/jsr166-tests/src/test/java/jsr166/PhaserTest.java
+++ b/jsr166-tests/src/test/java/jsr166/PhaserTest.java
@@ -527,7 +527,7 @@ public class PhaserTest extends JSR166TestCase {
}});
await(pleaseArrive);
- waitForThreadToEnterWaitState(t, SHORT_DELAY_MS);
+ waitForThreadToEnterWaitState(t);
assertEquals(0, phaser.arrive());
awaitTermination(t);
@@ -555,7 +555,7 @@ public class PhaserTest extends JSR166TestCase {
}});
await(pleaseArrive);
- waitForThreadToEnterWaitState(t, SHORT_DELAY_MS);
+ waitForThreadToEnterWaitState(t);
t.interrupt();
assertEquals(0, phaser.arrive());
awaitTermination(t);
@@ -571,20 +571,20 @@ public class PhaserTest extends JSR166TestCase {
public void testArriveAndAwaitAdvanceAfterInterrupt() {
final Phaser phaser = new Phaser();
assertEquals(0, phaser.register());
- final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
+ final CountDownLatch pleaseArrive = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() {
Thread.currentThread().interrupt();
assertEquals(0, phaser.register());
- pleaseInterrupt.countDown();
+ pleaseArrive.countDown();
assertTrue(Thread.currentThread().isInterrupted());
assertEquals(1, phaser.arriveAndAwaitAdvance());
- assertTrue(Thread.currentThread().isInterrupted());
+ assertTrue(Thread.interrupted());
}});
- await(pleaseInterrupt);
- waitForThreadToEnterWaitState(t, SHORT_DELAY_MS);
+ await(pleaseArrive);
+ waitForThreadToEnterWaitState(t);
Thread.currentThread().interrupt();
assertEquals(1, phaser.arriveAndAwaitAdvance());
assertTrue(Thread.interrupted());
@@ -605,11 +605,11 @@ public class PhaserTest extends JSR166TestCase {
assertFalse(Thread.currentThread().isInterrupted());
pleaseInterrupt.countDown();
assertEquals(1, phaser.arriveAndAwaitAdvance());
- assertTrue(Thread.currentThread().isInterrupted());
+ assertTrue(Thread.interrupted());
}});
await(pleaseInterrupt);
- waitForThreadToEnterWaitState(t, SHORT_DELAY_MS);
+ waitForThreadToEnterWaitState(t);
t.interrupt();
Thread.currentThread().interrupt();
assertEquals(1, phaser.arriveAndAwaitAdvance());
@@ -784,7 +784,7 @@ public class PhaserTest extends JSR166TestCase {
assertEquals(THREADS, phaser.getArrivedParties());
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
for (Thread thread : threads)
- waitForThreadToEnterWaitState(thread, SHORT_DELAY_MS);
+ waitForThreadToEnterWaitState(thread);
for (Thread thread : threads)
assertTrue(thread.isAlive());
assertState(phaser, 0, THREADS + 1, 1);