Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 557b2a5a authored by JW Wang's avatar JW Wang
Browse files

Clean up rollbacks after each test (2/n)

testNetworkPassedDoesNotRollback leaves a rollback for the network stack
and we need to clean up all rollbacks before running
testNativeWatchdogTriggersRollback otherwise the test will fail on
devices which doesn't support checkpoint.

See b/146991129 comment#2 for the detail.

Bug: 147259494
Test: atest StagedRollbackTest
Change-Id: Ib9c5e3f56bf31bfbf6f5a415879f9eb1b10d270e
parent f86cecf8
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -392,11 +392,6 @@ public class StagedRollbackTest {
        assertThat(RollbackUtils.getAvailableRollback(getModuleMetadataPackageName())).isNotNull();
    }

    @Test
    public void testRollbackWhitelistedApp_cleanUp() throws Exception {
        RollbackUtils.getRollbackManager().expireRollbackForPackage(getModuleMetadataPackageName());
    }

    @Test
    public void testRollbackDataPolicy_Phase1() throws Exception {
        Uninstall.packages(TestApp.A, TestApp.B);
@@ -435,6 +430,16 @@ public class StagedRollbackTest {
        assertThat(InstallUtils.getUserDataVersion(TestApp.B)).isEqualTo(1);
    }

    @Test
    public void testCleanUp() throws Exception {
        // testNativeWatchdogTriggersRollback will fail if multiple staged sessions are
        // committed on a device which doesn't support checkpoint. Let's clean up all rollbacks
        // so there is only one rollback to commit when testing native crashes.
        RollbackManager rm  = RollbackUtils.getRollbackManager();
        rm.getAvailableRollbacks().stream().flatMap(info -> info.getPackages().stream())
                .map(info -> info.getPackageName()).forEach(rm::expireRollbackForPackage);
    }

    private static void runShellCommand(String cmd) {
        ParcelFileDescriptor pfd = InstrumentationRegistry.getInstrumentation().getUiAutomation()
                .executeShellCommand(cmd);
+9 −10
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static org.testng.Assert.assertThrows;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -52,6 +53,11 @@ public class StagedRollbackTest extends BaseHostJUnit4Test {
        getDevice().reboot();
    }

    @After
    public void tearDown() throws Exception {
        runPhase("testCleanUp");
    }

    /**
     * Tests watchdog triggered staged rollbacks involving only apks.
     */
@@ -164,16 +170,9 @@ public class StagedRollbackTest extends BaseHostJUnit4Test {
     */
    @Test
    public void testRollbackWhitelistedApp() throws Exception {
        try {
        runPhase("testRollbackWhitelistedApp_Phase1");
        getDevice().reboot();
        runPhase("testRollbackWhitelistedApp_Phase2");
        } finally {
            // testNativeWatchdogTriggersRollback will fail if multiple staged sessions are
            // committed on a device which doesn't support checkpoint. Let's clean up the rollback
            // so there is only one rollback to commit when testing native crashes.
            runPhase("testRollbackWhitelistedApp_cleanUp");
        }
    }

    @Test