summaryrefslogtreecommitdiffstats
path: root/harmony-tests
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2015-02-18 09:57:21 -0800
committerMathieu Chartier <mathieuc@google.com>2015-02-18 11:34:25 -0800
commite7b8456e69c72dffc1c561c68cc320abfa6af241 (patch)
treeb8ed7b82b6d3d80064afce1e4406ffe6f870f982 /harmony-tests
parenta9c24ad83f3cd18738268559169ba901b5f70232 (diff)
downloadlibcore-e7b8456e69c72dffc1c561c68cc320abfa6af241.zip
libcore-e7b8456e69c72dffc1c561c68cc320abfa6af241.tar.gz
libcore-e7b8456e69c72dffc1c561c68cc320abfa6af241.tar.bz2
Make ReferenceQueueTest#test_removeJ more robust.
No spurrious failures if the sleep finishes before the RemoveThread is inside the try catch block. Bug: 19384923 Change-Id: I81e340e97eff5e1d011e980c2f89dfa679662547
Diffstat (limited to 'harmony-tests')
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ref/ReferenceQueueTest.java17
1 files changed, 10 insertions, 7 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ref/ReferenceQueueTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ref/ReferenceQueueTest.java
index 75a5218..e010116 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ref/ReferenceQueueTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/lang/ref/ReferenceQueueTest.java
@@ -22,6 +22,7 @@ import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
+import java.util.concurrent.CountDownLatch;
import libcore.java.lang.ref.FinalizationTester;
public class ReferenceQueueTest extends junit.framework.TestCase {
@@ -198,27 +199,29 @@ public class ReferenceQueueTest extends junit.framework.TestCase {
assertNull(rq.poll());
class RemoveThread extends Thread {
+ public final CountDownLatch inBlock = new CountDownLatch(1);
+ public final CountDownLatch outOfBlock = new CountDownLatch(1);
public void run() {
try {
+ inBlock.countDown();
rq.remove(1000L);
} catch(InterruptedException ie) {
isThrown = true;
}
+ outOfBlock.countDown();
}
}
RemoveThread rt = new RemoveThread();
rt.start();
try {
+ rt.inBlock.await();
+ // Try to be inside of rq.remove(1000L) if possible.
Thread.sleep(10);
- } catch(InterruptedException ie) {
-
- }
+ } catch(InterruptedException ie) {}
rt.interrupt();
try {
- Thread.sleep(10);
- } catch(InterruptedException ie) {
-
- }
+ rt.outOfBlock.await();
+ } catch(InterruptedException ie) {}
assertTrue(isThrown);
assertNull(rq.poll());