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

Commit 05ebdd40 authored by JW Wang's avatar JW Wang
Browse files

Rewrite testNetworkFailedRollback_Phase3 (1/n)

Move test code to device side so we can assert reboot more reliably.

Bug: 143035398
Test: atest StagedRollbackTest
Change-Id: I84f65ce17ad38b524b26436933f9c090c1b581c5
parent 181c51f1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ java_test_host {
    name: "StagedRollbackTest",
    srcs: ["StagedRollbackTest/src/**/*.java"],
    libs: ["tradefed"],
    static_libs: ["testng"],
    test_suites: ["general-tests"],
    test_config: "StagedRollbackTest.xml",
}
+11 −3
Original line number Diff line number Diff line
@@ -229,13 +229,21 @@ public class StagedRollbackTest {
        RollbackManager rm = RollbackUtils.getRollbackManager();
        assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(),
                        getNetworkStackPackageName())).isNotNull();

        // Sleep for < health check deadline
        Thread.sleep(TimeUnit.SECONDS.toMillis(5));
        // Verify rollback was not executed before health check deadline
        assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(),
                        getNetworkStackPackageName())).isNull();
    }

    @Test
    public void testNetworkFailedRollback_Phase3() throws Exception {
        RollbackManager rm = RollbackUtils.getRollbackManager();
        assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(),
                        getNetworkStackPackageName())).isNull();
        // Sleep for > health check deadline
        // The device is expected to reboot during sleeping. This device method will fail and
        // the host will catch the assertion. If reboot doesn't happen, the host will fail the
        // assertion.
        Thread.sleep(TimeUnit.SECONDS.toMillis(260));
    }

    @Test
+2 −16
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.tests.rollback.host;

import static org.junit.Assert.assertTrue;
import static org.testng.Assert.assertThrows;

import com.android.ddmlib.Log.LogLevel;
import com.android.tradefed.log.LogUtil.CLog;
@@ -136,22 +137,7 @@ public class StagedRollbackTest extends BaseHostJUnit4Test {

        // Verify rollback was enabled
        runPhase("testNetworkFailedRollback_Phase2");

        // Sleep for < health check deadline
        Thread.sleep(5000);
        // Verify rollback was not executed before health check deadline
        runPhase("testNetworkFailedRollback_Phase3");
        try {
            // This is expected to fail due to the device being rebooted out
            // from underneath the test. If this fails for reasons other than
            // the device reboot, those failures should result in failure of
            // the testNetworkFailedRollback_Phase4 phase.
            CLog.logAndDisplay(LogLevel.INFO, "Sleep and expect to fail while sleeping");
            // Sleep for > health check deadline
            Thread.sleep(260000);
        } catch (AssertionError e) {
            // AssertionError is expected.
        }
        assertThrows(AssertionError.class, () -> runPhase("testNetworkFailedRollback_Phase3"));

        getDevice().waitForDeviceAvailable();
        // Verify rollback was executed after health check deadline