diff options
author | 2020-09-24 10:13:10 +0100 | |
---|---|---|
committer | 2020-09-24 10:25:50 +0100 | |
commit | 9ce741b666ad33adb719cbdb710b51428bfa3518 (patch) | |
tree | b0c1007535e26145c820ebd4240ee48b8125066c /tests/ManagedProfileLifecycleStressTest | |
parent | 56b327db8854096221c60d181e953159ebda850e (diff) |
Add ManagedProfileLifecycleStressTest#testCreateStartDeleteStable
Added a similar test to
ManagedProfileLifecycleStressTest#testCreateStartDelete but with
waitForBroadcastIdle after each user operation. This is just a temp
test to identify if adding the sleeps after user operations reduces
flakiness.
Test: atest ManagedProfileLifecycleStressTest
Change-Id: I6ace688694248f61489d31148777031bd383c887
Diffstat (limited to 'tests/ManagedProfileLifecycleStressTest')
-rw-r--r-- | tests/ManagedProfileLifecycleStressTest/src/com/android/test/stress/ManagedProfileLifecycleStressTest.java | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/tests/ManagedProfileLifecycleStressTest/src/com/android/test/stress/ManagedProfileLifecycleStressTest.java b/tests/ManagedProfileLifecycleStressTest/src/com/android/test/stress/ManagedProfileLifecycleStressTest.java index 026677e09bed..99dde859028a 100644 --- a/tests/ManagedProfileLifecycleStressTest/src/com/android/test/stress/ManagedProfileLifecycleStressTest.java +++ b/tests/ManagedProfileLifecycleStressTest/src/com/android/test/stress/ManagedProfileLifecycleStressTest.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import com.android.tradefed.device.CollectingOutputReceiver; import com.android.tradefed.log.LogUtil.CLog; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; @@ -62,13 +63,62 @@ public class ManagedProfileLifecycleStressTest extends BaseHostJUnit4Test { CLog.w("Iteration N" + iteration); final int userId = createManagedProfile(); startUser(userId); - installPackageAsUser(DUMMY_DPC_APK, true /* grantPermissions */, userId, "-t"); + installPackageAsUser( + DUMMY_DPC_APK, /* grantPermissions= */true, userId, /* options= */"-t"); setProfileOwner(DUMMY_DPC_COMPONENT, userId); removeUser(userId); } CLog.w("Completed " + iteration + " iterations."); } + /** + * Create, start, and kill managed profiles in a loop with waitForBroadcastIdle after each user + * operation. + */ + @Test + public void testCreateStartDeleteStable() throws Exception { + // Disable package verifier for ADB installs. + getDevice().executeShellCommand("settings put global verifier_verify_adb_installs 0"); + int iteration = 0; + final long deadline = System.nanoTime() + TimeUnit.MINUTES.toNanos(TIME_LIMIT_MINUTES); + while (System.nanoTime() < deadline) { + iteration++; + CLog.w("Iteration N" + iteration); + final int userId = createManagedProfile(); + waitForBroadcastIdle(); + + startUser(userId); + waitForBroadcastIdle(); + + installPackageAsUser( + DUMMY_DPC_APK, /* grantPermissions= */true, userId, /* options= */"-t"); + + setProfileOwner(DUMMY_DPC_COMPONENT, userId); + + removeUser(userId); + waitForBroadcastIdle(); + } + CLog.w("Completed " + iteration + " iterations."); + } + + private void waitForBroadcastIdle() throws Exception { + final CollectingOutputReceiver receiver = new CollectingOutputReceiver(); + // We allow 8min for the command to complete and 4min for the command to start to + // output something. + getDevice().executeShellCommand( + "am wait-for-broadcast-idle", + receiver, + /* maxTimeoutForCommand= */8, + /* maxTimeoutToOutputShellResponse= */4, + TimeUnit.MINUTES, + /* retryAttempts= */0); + final String output = receiver.getOutput(); + if (!output.contains("All broadcast queues are idle!")) { + CLog.e("Output from 'am wait-for-broadcast-idle': %s", output); + fail("'am wait-for-broadcase-idle' did not complete."); + } + } + private int createManagedProfile() throws Exception { final String output = getDevice().executeShellCommand( "pm create-user --profileOf 0 --managed TestProfile"); |