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)