summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alex Light <allight@google.com> 2018-11-30 14:08:03 -0800
committer Alex Light <allight@google.com> 2018-11-30 14:57:43 -0800
commite059238fbc2ca3806d20895bd87d1e3ebfe0d4ee (patch)
tree7b8c44040a65b8d387319725d7392cd01acd64ca
parent427766c709b762f01f2bb92143bf33ece1c88290 (diff)
Make test 924 more consistent.
Test 924 was flaking due to relying on timing between threads and short time windows. This lengthens the time windows and tries to test for the desired state more directly Test: stress --cpu 100 &; while ./test/run-test --host 924; do; done Bug: 62117833 Change-Id: I5119255afbd793ae92358250281b77c783381b2d
-rw-r--r--test/924-threads/src/art/Test924.java49
1 files changed, 36 insertions, 13 deletions
diff --git a/test/924-threads/src/art/Test924.java b/test/924-threads/src/art/Test924.java
index e8e97817b7..e97c9c6b35 100644
--- a/test/924-threads/src/art/Test924.java
+++ b/test/924-threads/src/art/Test924.java
@@ -27,6 +27,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.time.Instant;
public class Test924 {
public static void run() throws Exception {
@@ -109,6 +110,7 @@ public class Test924 {
final CountDownLatch cdl4 = new CountDownLatch(1);
final CountDownLatch cdl5 = new CountDownLatch(1);
final Holder h = new Holder();
+ final long ALMOST_INFINITE = 100000000; // 1.1 days!
final NativeWaiter w = new NativeWaiter();
Runnable r = new Runnable() {
@Override
@@ -121,7 +123,7 @@ public class Test924 {
cdl2.countDown();
synchronized(cdl2) {
- cdl2.wait(1000); // Wait a second.
+ cdl2.wait(ALMOST_INFINITE);
}
cdl3_1.await();
@@ -131,7 +133,9 @@ public class Test924 {
}
cdl4.countDown();
- Thread.sleep(1000);
+ try {
+ Thread.sleep(ALMOST_INFINITE);
+ } catch (InterruptedException e) { }
cdl5.countDown();
while (!h.flag) {
@@ -152,18 +156,20 @@ public class Test924 {
// Waiting.
cdl1.await();
- Thread.yield();
- Thread.sleep(100);
- printThreadState(t);
+ // This is super inconsistent so just wait for the desired state for up to 5 minutes then give
+ // up and continue
+ final int WAITING_INDEF = 0x191;
+ waitForState(t, WAITING_INDEF);
synchronized(cdl1) {
cdl1.notifyAll();
}
// Timed waiting.
cdl2.await();
- Thread.yield();
- Thread.sleep(100);
- printThreadState(t);
+ // This is super inconsistent so just wait for the desired state for up to 5 minutes then give
+ // up and continue
+ final int WAITING_TIMED = 0x1a1;
+ waitForState(t, WAITING_TIMED);
synchronized(cdl2) {
cdl2.notifyAll();
}
@@ -185,14 +191,16 @@ public class Test924 {
// Sleeping.
cdl4.await();
- Thread.yield();
- Thread.sleep(100);
- printThreadState(t);
+ // This is super inconsistent so just wait for the desired state for up to 5 minutes then give
+ // up and continue
+ final int WAITING_SLEEP = 0xe1;
+ waitForState(t, WAITING_SLEEP);
+ t.interrupt();
// Running.
cdl5.await();
Thread.yield();
- Thread.sleep(100);
+ Thread.sleep(1000);
printThreadState(t);
h.flag = true;
@@ -204,11 +212,26 @@ public class Test924 {
// Dying.
t.join();
Thread.yield();
- Thread.sleep(100);
+ Thread.sleep(1000);
printThreadState(t);
}
+ private static void waitForState(Thread t, int desired) throws Exception {
+ Thread.yield();
+ Thread.sleep(1000);
+ // This is super inconsistent so just wait for the desired state for up to 5 minutes then give
+ // up and continue
+ int state;
+ Instant deadline = Instant.now().plusSeconds(60 * 5);
+ while ((state = getThreadState(t)) != desired && deadline.isAfter(Instant.now())) {
+ Thread.yield();
+ Thread.sleep(100);
+ Thread.yield();
+ }
+ printThreadState(state);
+ }
+
private static void doAllThreadsTests() {
Thread[] threads = getAllThreads();
List<Thread> threadList = new ArrayList<>(Arrays.asList(threads));