Skip to content
Snippets Groups Projects
Commit c726ac66 authored by Gavin Corkery's avatar Gavin Corkery
Browse files

Move last crash to trigger rollback to host side

Now it is possible for reboot to happen before the device test
completes and fail the test.

Let's move the last crash to trigger rollback to host side to
avoid this problem.

Bug: 178159821
Test: atest StagedRollbackTest
Change-Id: I7db8d8a585c6d42be7f8017b55fbd4c547d7b56a
Merged-In: I7db8d8a585c6d42be7f8017b55fbd4c547d7b56a
(cherry picked from commit d32e3526)
parent 944eece7
No related branches found
No related tags found
No related merge requests found
......@@ -124,22 +124,12 @@ public class StagedRollbackTest {
Thread.sleep(TimeUnit.SECONDS.toMillis(30));
}
/**
* Test rollbacks of staged installs involving only apks with bad update.
* Trigger rollback phase.
*/
@Test
public void testBadApkOnly_Phase3_Crash() throws Exception {
// One more crash to trigger rollback
RollbackUtils.sendCrashBroadcast(TestApp.A, 1);
}
/**
* Test rollbacks of staged installs involving only apks.
* Confirm rollback phase.
*/
@Test
public void testBadApkOnly_Phase4_VerifyRollback() throws Exception {
public void testBadApkOnly_Phase3_VerifyRollback() throws Exception {
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
InstallUtils.processUserData(TestApp.A);
......@@ -447,8 +437,10 @@ public class StagedRollbackTest {
Rollback.from(TEST_APEX_WITH_APK_V2).to(TEST_APEX_WITH_APK_V1),
Rollback.from(TestApp.A, 0).to(TestApp.A1));
// Crash TestApp.A PackageWatchdog#TRIGGER_FAILURE_COUNT times to trigger rollback
RollbackUtils.sendCrashBroadcast(TestApp.A, 5);
// Crash TestApp.A PackageWatchdog#TRIGGER_FAILURE_COUNT-1 times
RollbackUtils.sendCrashBroadcast(TestApp.A, 4);
// Sleep for a while to make sure we don't trigger rollback
Thread.sleep(TimeUnit.SECONDS.toMillis(30));
}
@Test
......
......@@ -153,13 +153,14 @@ public class StagedRollbackTest extends BaseHostJUnit4Test {
getDevice().reboot();
runPhase("testBadApkOnly_Phase2_VerifyInstall");
// Trigger rollback and wait for reboot to happen
runPhase("testBadApkOnly_Phase3_Crash");
// Launch the app to crash to trigger rollback
startActivity(TESTAPP_A);
// Wait for reboot to happen
waitForDeviceNotAvailable(2, TimeUnit.MINUTES);
getDevice().waitForDeviceAvailable();
runPhase("testBadApkOnly_Phase4_VerifyRollback");
runPhase("testBadApkOnly_Phase3_VerifyRollback");
assertThat(mLogger).eventOccurred(ROLLBACK_INITIATE, null, REASON_APP_CRASH, TESTAPP_A);
assertThat(mLogger).eventOccurred(ROLLBACK_BOOT_TRIGGERED, null, null, null);
......@@ -304,8 +305,10 @@ public class StagedRollbackTest extends BaseHostJUnit4Test {
getDevice().reboot();
// Verify apex was installed and then crash the apk
runPhase("testRollbackApexWithApkCrashing_Phase2_Crash");
// Wait for crash to trigger rollback
waitForDeviceNotAvailable(5, TimeUnit.MINUTES);
// Launch the app to crash to trigger rollback
startActivity(TESTAPP_A);
// Wait for reboot to happen
waitForDeviceNotAvailable(2, TimeUnit.MINUTES);
getDevice().waitForDeviceAvailable();
// Verify rollback occurred due to crash of apk-in-apex
runPhase("testRollbackApexWithApkCrashing_Phase3_VerifyRollback");
......@@ -631,6 +634,12 @@ public class StagedRollbackTest extends BaseHostJUnit4Test {
}
}
private void startActivity(String packageName) throws Exception {
String cmd = "am start -S -a android.intent.action.MAIN "
+ "-c android.intent.category.LAUNCHER " + packageName;
getDevice().executeShellCommand(cmd);
}
private void crashProcess(String processName, int numberOfCrashes) throws Exception {
String pid = "";
String lastPid = "invalid";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment