From 4c6a8fc2e2e2642dd17a6db0e9a84c93e0298414 Mon Sep 17 00:00:00 2001 From: Yunfan Chen Date: Wed, 13 May 2020 14:47:38 +0900 Subject: [PATCH] Fix OOM when running testAddRemoveRace The test has been very likely to fail with OOM error or process crashes. This is because we repeatedly creating ActivityRecord/ActivityStack/Task in the test. Even though we release it after each run, the GC can still throw OOM because of reference by mocking is not released while running the test. After receiving several OOM's, the test process will crash. To fix this issue, simply re-use the same ActivityRecord instead of creating one per loop run. This works for this test as we only care about the starting window handling inside ActivityRecord. Test: atest AppWindowTokenTests#testAddRemoveRace Bug: 130392471 Change-Id: I7df942d364ee07e179b05b6f837494c475197d7c --- .../src/com/android/server/wm/AppWindowTokenTests.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java b/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java index 5c21853b1f598..9263d8a2f9e3f 100644 --- a/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/AppWindowTokenTests.java @@ -316,20 +316,16 @@ public class AppWindowTokenTests extends WindowTestsBase { } @Test - @FlakyTest(bugId = 130392471) public void testAddRemoveRace() { // There was once a race condition between adding and removing starting windows + final ActivityRecord appToken = mAppWindow.mActivityRecord; for (int i = 0; i < 1000; i++) { - final ActivityRecord appToken = createIsolatedTestActivityRecord(); - appToken.addStartingWindow(mPackageName, android.R.style.Theme, null, "Test", 0, 0, 0, 0, null, true, true, false, true, false, false); appToken.removeStartingWindow(); waitUntilHandlersIdle(); assertNoStartingWindow(appToken); - - appToken.getParent().getParent().removeImmediately(); } }