From 5d760e2a117a63f2339af5ccfd9a2f81126893e1 Mon Sep 17 00:00:00 2001 From: judds Date: Fri, 1 Dec 2017 12:31:43 -0800 Subject: [PATCH] Fail CachingTest if our weak reference is never cleared. 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 --- .../androidTest/java/com/bumptech/glide/CachingTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/instrumentation/src/androidTest/java/com/bumptech/glide/CachingTest.java b/instrumentation/src/androidTest/java/com/bumptech/glide/CachingTest.java index 0b115225ad..b17001dd69 100644 --- a/instrumentation/src/androidTest/java/com/bumptech/glide/CachingTest.java +++ b/instrumentation/src/androidTest/java/com/bumptech/glide/CachingTest.java @@ -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(); @@ -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)