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
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user