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

Commit 94b0adcf authored by JW Wang's avatar JW Wang
Browse files

Rewrite testBadApkOnly_Phase3 (1/n)

1. Wait for 120s for reboot to happen. This improve the stablity of
   virtual devices which sometimes could be slow in shutdown.
2. Use assertThrows to catch exception when reboot doesn't happen which
   gives us better error messages than expecting next phase to fail.

Bug: 143999213
Test: atest StagedRollbackTest#testBadApkOnly
Change-Id: Ibafcbe7e003fb92991d6f8fe2fde7b344ffd6db6
parent 46214265
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -21,8 +21,6 @@ import static com.android.cts.rollback.lib.RollbackUtils.getUniqueRollbackInfoFo

import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.fail;

import android.Manifest;
import android.annotation.Nullable;
import android.content.ComponentName;
@@ -155,10 +153,9 @@ public class StagedRollbackTest {
        RollbackUtils.sendCrashBroadcast(TestApp.A, 1);

        // We expect the device to be rebooted automatically. Wait for that to happen.
        Thread.sleep(30 * 1000);

        // Raise an error anyway if reboot didn't happen.
        fail("watchdog did not trigger reboot");
        // 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(120));
    }

    /**
+1 −12
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@ 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;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;

@@ -57,17 +55,8 @@ public class StagedRollbackTest extends BaseHostJUnit4Test {
        runPhase("testBadApkOnly_Phase1");
        getDevice().reboot();
        runPhase("testBadApkOnly_Phase2");
        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 testApkOnlyConfirmRollback phase.
            CLog.logAndDisplay(LogLevel.INFO, "testBadApkOnlyTriggerRollback is expected to fail");
            runPhase("testBadApkOnly_Phase3");
        } catch (AssertionError e) {
            // AssertionError is expected.
        }

        assertThrows(AssertionError.class, () -> runPhase("testBadApkOnly_Phase3"));
        getDevice().waitForDeviceAvailable();

        runPhase("testBadApkOnly_Phase4");