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

Commit 87fba4c1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Take timestamp before causing ANR in the test" into main

parents e05224b0 3c712594
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ class AnrTest {

    private fun clickCloseAppOnAnrDialog() {
        // Find anr dialog and kill app
        val timestamp = System.currentTimeMillis()
        val uiDevice: UiDevice = UiDevice.getInstance(instrumentation)
        val closeAppButton: UiObject2? =
                uiDevice.wait(Until.findObject(By.res("android:id/aerr_close")), 20000)
@@ -107,7 +108,6 @@ class AnrTest {
            fail("Could not find anr dialog")
            return
        }
        val initialReasons = getExitReasons()
        closeAppButton.click()
        /**
         * We must wait for the app to be fully closed before exiting this test. This is because
@@ -116,7 +116,7 @@ class AnrTest {
         * the killing logic will apply to the newly launched 'am start' instance, and the second
         * test will fail because the unresponsive activity will never be launched.
         */
        waitForNewExitReason(initialReasons[0].timestamp)
        waitForNewExitReasonAfter(timestamp)
    }

    private fun clickWaitOnAnrDialog() {
@@ -140,12 +140,13 @@ class AnrTest {
        return infos
    }

    private fun waitForNewExitReason(previousExitTimestamp: Long) {
    private fun waitForNewExitReasonAfter(timestamp: Long) {
        PollingCheck.waitFor {
            getExitReasons()[0].timestamp > previousExitTimestamp
            val reasons = getExitReasons()
            !reasons.isEmpty() && reasons[0].timestamp >= timestamp
        }
        val reasons = getExitReasons()
        assertTrue(reasons[0].timestamp > previousExitTimestamp)
        assertTrue(reasons[0].timestamp > timestamp)
        assertEquals(ApplicationExitInfo.REASON_ANR, reasons[0].reason)
    }