fix some timeouts in this test

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1394134 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2012-10-04 16:21:37 +00:00
parent 690a6a0e13
commit 5e144ab7bb

View File

@ -40,18 +40,18 @@ public class TestDocumentsWriterStallControl extends LuceneTestCase {
start(waitThreads); start(waitThreads);
assertFalse(ctrl.hasBlocked()); assertFalse(ctrl.hasBlocked());
assertFalse(ctrl.anyStalledThreads()); assertFalse(ctrl.anyStalledThreads());
join(waitThreads, 10); join(waitThreads);
// now stall threads and wake them up again // now stall threads and wake them up again
ctrl.updateStalled(true); ctrl.updateStalled(true);
waitThreads = waitThreads(atLeast(1), ctrl); waitThreads = waitThreads(atLeast(1), ctrl);
start(waitThreads); start(waitThreads);
awaitState(100, Thread.State.WAITING, waitThreads); awaitState(Thread.State.WAITING, waitThreads);
assertTrue(ctrl.hasBlocked()); assertTrue(ctrl.hasBlocked());
assertTrue(ctrl.anyStalledThreads()); assertTrue(ctrl.anyStalledThreads());
ctrl.updateStalled(false); ctrl.updateStalled(false);
assertFalse(ctrl.anyStalledThreads()); assertFalse(ctrl.anyStalledThreads());
join(waitThreads, 500); join(waitThreads);
} }
public void testRandom() throws InterruptedException { public void testRandom() throws InterruptedException {
@ -90,7 +90,7 @@ public class TestDocumentsWriterStallControl extends LuceneTestCase {
} }
} }
join(stallThreads, 100); join(stallThreads);
} }
@ -306,10 +306,10 @@ public class TestDocumentsWriterStallControl extends LuceneTestCase {
Thread.sleep(1); // let them start Thread.sleep(1); // let them start
} }
public static void join(Thread[] toJoin, long timeout) public static void join(Thread[] toJoin)
throws InterruptedException { throws InterruptedException {
for (Thread thread : toJoin) { for (Thread thread : toJoin) {
thread.join(timeout); thread.join();
} }
} }
@ -325,11 +325,12 @@ public class TestDocumentsWriterStallControl extends LuceneTestCase {
} }
return array; return array;
} }
public static void awaitState(long timeout, Thread.State state, /** Waits for all incoming threads to be in wait()
* methods. */
public static void awaitState(Thread.State state,
Thread... threads) throws InterruptedException { Thread... threads) throws InterruptedException {
long t = System.currentTimeMillis(); while (true) {
while (System.currentTimeMillis() - t <= timeout) {
boolean done = true; boolean done = true;
for (Thread thread : threads) { for (Thread thread : threads) {
if (thread.getState() != state) { if (thread.getState() != state) {
@ -345,8 +346,6 @@ public class TestDocumentsWriterStallControl extends LuceneTestCase {
Thread.sleep(1); Thread.sleep(1);
} }
} }
fail("timed out waiting for state: " + state + " timeout: " + timeout
+ " ms");
} }
private static final class Synchronizer { private static final class Synchronizer {