diff options
| author | 2022-08-24 17:29:42 +0100 | |
|---|---|---|
| committer | 2022-08-24 17:29:42 +0100 | |
| commit | b36216ba0d60339bc9875df2481cda542a0c82e8 (patch) | |
| tree | 6477cd13525ccf47a888fc64806b1b025aa4d5b9 | |
| parent | cb2ec7b31dfb53ac70f189eb2db2aeef4c00e42f (diff) | |
wait-for-broadcast-idle before stopUser in UserLifecycleTests.
Stopping a user heavily depends on broadcast queue, and that gets
crowded after user creation and switches. Which leads to a timeout
on stopping user. This CL makes sure broadcast queue is idle before
stopping a user, to prevent the timeout.
Bug: 200217686
Test: atest MultiUserPerfTests:android.multiuser.UserLifecycleTests --no-bazel-mode
Change-Id: I540a73d436eb28600e689c27e27ec6259d37e8b7
| -rw-r--r-- | apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java b/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java index 448ee6160ce0..8369b37f0172 100644 --- a/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java +++ b/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java @@ -425,7 +425,7 @@ public class UserLifecycleTests { final int userId = createManagedProfile(); // Start the profile initially, then stop it. Similar to setQuietModeEnabled. startUserInBackgroundAndWaitForUnlock(userId); - stopUser(userId, true); + stopUserAfterWaitingForBroadcastIdle(userId, true); mRunner.resumeTiming(); Log.i(TAG, "Starting timer"); @@ -480,7 +480,7 @@ public class UserLifecycleTests { installPreexistingApp(userId, DUMMY_PACKAGE_NAME); startUserInBackgroundAndWaitForUnlock(userId); startApp(userId, DUMMY_PACKAGE_NAME); - stopUser(userId, true); + stopUserAfterWaitingForBroadcastIdle(userId, true); SystemClock.sleep(1_000); // 1 second cool-down before re-starting profile. mRunner.resumeTiming(); Log.i(TAG, "Starting timer"); @@ -677,6 +677,19 @@ public class UserLifecycleTests { return success[0]; } + /** + * Waits for broadcast idle before stopping a user, to prevent timeouts on stop user. + * Stopping a user heavily depends on broadcast queue, and that gets crowded after user creation + * or user switches, which leads to a timeout on stopping user and cause the tests to be flaky. + * Do not call this method while timing is on. i.e. between mRunner.resumeTiming() and + * mRunner.pauseTiming(). Otherwise it would cause the test results to be spiky. + */ + private void stopUserAfterWaitingForBroadcastIdle(int userId, boolean force) + throws RemoteException { + ShellHelper.runShellCommand("am wait-for-broadcast-idle"); + stopUser(userId, force); + } + private void stopUser(int userId, boolean force) throws RemoteException { final CountDownLatch latch = new CountDownLatch(1); mIam.stopUser(userId, force /* force */, new IStopUserCallback.Stub() { @@ -712,7 +725,7 @@ public class UserLifecycleTests { attestTrue("Didn't switch back to user, " + origUser, origUser == mAm.getCurrentUser()); if (stopNewUser) { - stopUser(testUser, true); + stopUserAfterWaitingForBroadcastIdle(testUser, true); attestFalse("Failed to stop user " + testUser, mAm.isUserRunning(testUser)); } |