From e3c63c41d4dc5956b734b67d32fedf8e006028dd Mon Sep 17 00:00:00 2001 From: Saket Narayan Date: Wed, 13 Nov 2024 01:50:32 -0500 Subject: [PATCH] Add debug logs to investigate flaky activity recreations --- .../telephoto/zoomable/ActivityRecreationTester.kt | 10 ++++++++++ .../me/saket/telephoto/zoomable/ZoomableImageTest.kt | 1 + .../me/saket/telephoto/zoomable/screenOrientation.kt | 1 + 3 files changed, 12 insertions(+) diff --git a/zoomable-image/core/src/androidTest/kotlin/me/saket/telephoto/zoomable/ActivityRecreationTester.kt b/zoomable-image/core/src/androidTest/kotlin/me/saket/telephoto/zoomable/ActivityRecreationTester.kt index 7985436c..d9af5d42 100644 --- a/zoomable-image/core/src/androidTest/kotlin/me/saket/telephoto/zoomable/ActivityRecreationTester.kt +++ b/zoomable-image/core/src/androidTest/kotlin/me/saket/telephoto/zoomable/ActivityRecreationTester.kt @@ -2,8 +2,11 @@ package me.saket.telephoto.zoomable import androidx.activity.ComponentActivity import androidx.compose.runtime.Composable +import androidx.compose.ui.test.ComposeTimeoutException import androidx.compose.ui.test.junit4.AndroidComposeTestRule import androidx.test.ext.junit.rules.ActivityScenarioRule +import me.saket.telephoto.util.waitUntil +import kotlin.time.Duration.Companion.seconds // Workaround for https://issuetracker.google.com/issues/271226817. // Based on https://issuetracker.google.com/issues/271226817#comment5. @@ -18,8 +21,15 @@ class ActivityRecreationTester( } fun recreateWith(block: () -> Unit) { + val activityBefore = testRule.activity block() + try { + testRule.waitUntil(2.seconds) { activityBefore != testRule.activity } + } catch (e: ComposeTimeoutException) { + throw RuntimeException("Timed out waiting for the Activity to be recreated", e) + } + val composeTest = testRule::class.java.getDeclaredField("composeTest").also { it.isAccessible = true }.get(testRule) diff --git a/zoomable-image/core/src/androidTest/kotlin/me/saket/telephoto/zoomable/ZoomableImageTest.kt b/zoomable-image/core/src/androidTest/kotlin/me/saket/telephoto/zoomable/ZoomableImageTest.kt index b7c4e4a3..401bc77c 100644 --- a/zoomable-image/core/src/androidTest/kotlin/me/saket/telephoto/zoomable/ZoomableImageTest.kt +++ b/zoomable-image/core/src/androidTest/kotlin/me/saket/telephoto/zoomable/ZoomableImageTest.kt @@ -1520,6 +1520,7 @@ class ZoomableImageTest { (rule.onNodeWithTag("image")).run { performTouchInput { doubleClick(center - Offset(0f, 360f)) } } + rule.waitUntil { imageState.isImageDisplayedInFullQuality } rule.runOnIdle { dropshots.assertSnapshot(rule.activity, testName.methodName + "_[before_rotation]") } diff --git a/zoomable-image/core/src/androidTest/kotlin/me/saket/telephoto/zoomable/screenOrientation.kt b/zoomable-image/core/src/androidTest/kotlin/me/saket/telephoto/zoomable/screenOrientation.kt index 29f21d6b..21d26b7c 100644 --- a/zoomable-image/core/src/androidTest/kotlin/me/saket/telephoto/zoomable/screenOrientation.kt +++ b/zoomable-image/core/src/androidTest/kotlin/me/saket/telephoto/zoomable/screenOrientation.kt @@ -19,6 +19,7 @@ internal fun AndroidComposeTestRule