summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2014-06-24 19:42:36 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-06-24 19:42:36 +0000
commitfdf7f349f5744b442e7c45d54c45342d0301c961 (patch)
treef3c6cce9fdeedfedb92209835d01d4b18b37208a
parent81f6bab5bc9eb0236b30413d7ef3147c745f5dcf (diff)
parent47c61891491acce74675622abf3132ff03464ae5 (diff)
downloadlibcore-fdf7f349f5744b442e7c45d54c45342d0301c961.zip
libcore-fdf7f349f5744b442e7c45d54c45342d0301c961.tar.gz
libcore-fdf7f349f5744b442e7c45d54c45342d0301c961.tar.bz2
am 47c61891: am 31e8ef04: Merge "Fix race condition in WeakHashMapTest."
* commit '47c61891491acce74675622abf3132ff03464ae5': Fix race condition in WeakHashMapTest.
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/util/WeakHashMapTest.java17
1 files changed, 11 insertions, 6 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/WeakHashMapTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/WeakHashMapTest.java
index 0d34f72..1d5294f 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/WeakHashMapTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/WeakHashMapTest.java
@@ -199,13 +199,18 @@ public class WeakHashMapTest extends junit.framework.TestCase {
values = null;
keyArray[50] = null;
- int count = 0;
+ FinalizationTester.induceFinalization();
+ long startTime = System.currentTimeMillis();
+ // We use a busy wait loop here since we can not know when the ReferenceQueue
+ // daemon will enqueue the cleared references on their internal reference
+ // queues. The current timeout is 5 seconds.
do {
- System.gc();
- System.gc();
- FinalizationTester.induceFinalization();
- count++;
- } while (count <= 5 && entrySet.size() == 100);
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ }
+ } while (entrySet.size() != 99 &&
+ System.currentTimeMillis() - startTime < 5000);
assertTrue(
"Incorrect number of entries returned after gc--wanted 99, got: "