Skip to content
Snippets Groups Projects
Commit b259ee80 authored by KH Shi's avatar KH Shi Committed by Gerrit Code Review
Browse files

Merge "Fix TetheringServiceTest#testTetheringManagerLeak flaky"

parents f62267c7 b2549873
No related branches found
No related tags found
No related merge requests found
...@@ -664,17 +664,17 @@ public final class TetheringServiceTest { ...@@ -664,17 +664,17 @@ public final class TetheringServiceTest {
assertEquals("Internal callback is not registered", 1, callbacks.size()); assertEquals("Internal callback is not registered", 1, callbacks.size());
assertNotNull(weakTm.get()); assertNotNull(weakTm.get());
// Calling System.gc() or System.runFinalization() doesn't guarantee GCs or finalizers
// are executed synchronously. The finalizer is called after GC on a separate thread.
final int attempts = 100; final int attempts = 100;
final long waitIntervalMs = 50; final long waitIntervalMs = 50;
for (int i = 0; i < attempts; i++) { for (int i = 0; i < attempts; i++) {
forceGc(); forceGc();
if (weakTm.get() == null) break; if (weakTm.get() == null && callbacks.size() == 0) break;
Thread.sleep(waitIntervalMs); Thread.sleep(waitIntervalMs);
} }
assertNull("TetheringManager weak reference still not null after " + attempts assertNull("TetheringManager weak reference is not null", weakTm.get());
+ " attempts", weakTm.get());
assertEquals("Internal callback is not unregistered", 0, callbacks.size()); assertEquals("Internal callback is not unregistered", 0, callbacks.size());
}); });
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment