am 31e8ef04: Merge "Fix race condition in WeakHashMapTest."

* commit '31e8ef04eb3bc2029eb94393c3ce87245dd75da2':
  Fix race condition in WeakHashMapTest.
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 @@
         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: "