diff options
| author | 2023-09-20 19:19:29 +0000 | |
|---|---|---|
| committer | 2023-09-20 19:19:29 +0000 | |
| commit | 4e1de31d59a6a59120c80b0e4e467ae350d2d7fc (patch) | |
| tree | 10537113eb887d821bf0012243e17e9446f8cff4 | |
| parent | 24f3706615823e6feb78b3256430814e607ea18e (diff) | |
| parent | 0413179d77870950b548844baba357ed9b61c545 (diff) | |
Merge "Speed up PluginInstanceTest by skipping unnessecary gc runs" into main
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java b/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java index 88d853e244e0..8f06e636b479 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java @@ -181,29 +181,30 @@ public class PluginInstanceTest extends SysuiTestCase { String ACTION = "testAction"; } - public void assertInstances(Integer allocated, Integer created) { - // Run the garbage collector to finalize and deallocate outstanding - // instances. Since the GC doesn't always appear to want to run - // completely when we ask, we ask it 10 times in a short loop. - for (int i = 0; i < 10; i++) { + private void assertInstances(int allocated, int created) { + // If there are more than the expected number of allocated instances, then we run the + // garbage collector to finalize and deallocate any outstanding non-referenced instances. + // Since the GC doesn't always appear to want to run completely when we ask, we do this up + // to 10 times before failing the test. + for (int i = 0; mCounter.getAllocatedInstances() > allocated && i < 10; i++) { System.runFinalization(); System.gc(); } - mCounter.assertInstances(allocated, created); + assertEquals(allocated, mCounter.getAllocatedInstances()); + assertEquals(created, mCounter.getCreatedInstances()); } public static class RefCounter { public final AtomicInteger mAllocatedInstances = new AtomicInteger(); public final AtomicInteger mCreatedInstances = new AtomicInteger(); - public void assertInstances(Integer allocated, Integer created) { - if (allocated != null) { - assertEquals(allocated.intValue(), mAllocatedInstances.get()); - } - if (created != null) { - assertEquals(created.intValue(), mCreatedInstances.get()); - } + public int getAllocatedInstances() { + return mAllocatedInstances.get(); + } + + public int getCreatedInstances() { + return mCreatedInstances.get(); } } |