Skip to content

Commit

Permalink
Merge "Increase timeout for flaky WeakHashMap.test_keySet()"
Browse files Browse the repository at this point in the history
am: 171ae55

Change-Id: I4671cb85dbfded8f7a7781b5bb08d370ac8019f7
  • Loading branch information
15characterlimi authored and android-build-merger committed Dec 1, 2016
2 parents 54eb9a1 + 171ae55 commit 9a596f0
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,20 @@ public void test_keySet() {
long startTime = System.currentTimeMillis();
// We use a busy wait loop here since we cannot know when the ReferenceQueue
// daemon will enqueue the cleared references on their internal reference
// queues. The current timeout is 5 seconds.
// queues.
// The timeout after which the reference should be cleared. This test used to
// be flaky when it was set to 5 seconds. Daemons.MAX_FINALIZE_NANOS is
// currently 10 seconds so that seems like the correct value.
// We allow an extra 500msec buffer to minimize races between finalizer,
// keySet.size() evaluation and time check.
long timeout = 10000 + 500;
do {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
} while (keySet.size() != 99 &&
System.currentTimeMillis() - startTime < 5000);
System.currentTimeMillis() - startTime < timeout);

assertEquals("Incorrect number of keys returned after gc,", 99, keySet.size());
}
Expand Down

0 comments on commit 9a596f0

Please sign in to comment.