Skip to content

Commit

Permalink
Add debug logs to investigate flaky activity recreations
Browse files Browse the repository at this point in the history
  • Loading branch information
saket committed Nov 13, 2024
1 parent 21a3db3 commit e3c63c4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -18,8 +21,15 @@ class ActivityRecreationTester<A : ComponentActivity>(
}

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal fun <A : ComponentActivity> AndroidComposeTestRule<ActivityScenarioRule

if (currentOrientation != targetOrientation) {
runOnUiThread {
println("Changing orientation to $orientation")
activity.requestedOrientation = targetOrientation
}
this.waitForIdle()
Expand Down

0 comments on commit e3c63c4

Please sign in to comment.