Skip to content

Commit

Permalink
Fail CachingTest if our weak reference is never cleared.
Browse files Browse the repository at this point in the history
We're waiting for a specific condition that should occur, but it's
dependent on the VM. I haven't seen it fail with 100 attempts, but it's
possible it might. Failing with a specific assertion should make it
easier to distinguish between failed tests and flakes.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177625844
  • Loading branch information
sjudd committed Dec 4, 2017
1 parent 0e4c491 commit 5d760e2
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public void run() {
// Wait for the weak reference to be cleared and the request to be removed from active
// resources.
// De-flake by allowing multiple tries
boolean isWeakRefCleared = false;
for (int j = 0; j < 100; j++) {
Runtime.getRuntime().gc();
concurrency.pokeMainThread();
Expand All @@ -135,10 +136,15 @@ public void run() {
GlideApp.with(context).clear(target);
} catch (RuntimeException e) {
// The item has been cleared from active resources.
isWeakRefCleared = true;
break;
}
}

if (!isWeakRefCleared) {
fail("Failed to clear weak ref.");
}

concurrency.get(
GlideApp.with(context)
.load(ResourceIds.raw.canonical)
Expand Down

0 comments on commit 5d760e2

Please sign in to comment.