Afzal Najam
10/07/2022, 5:34 PMwithFrameMillis
to withInfiniteAnimationFrameMillis
, in the code, the UI test passed and the Node tree was correct.
My question is, is this a bug I should file?Afzal Najam
10/07/2022, 5:35 PM@Composable
fun CustomSnackbar(snackbarHostState: SnackbarHostState) {
val snackbarData = snackbarHostState.currentSnackbarData
Box(contentAlignment = Alignment.BottomCenter) {
AnimatedVisibility(
visible = snackbarData != null,
enter = fadeIn(),
exit = fadeOut(),
) {
LaunchedEffect(Unit) {
while(true) {
withFrameMillis { frameMs ->
}
}
}
Canvas(Modifier.fillMaxSize(), onDraw = {
drawRect(Color.Black, size = Size(100f, 100f))
})
}
SnackbarHost(hostState = snackbarHostState)
}
}
And here’s the UI test
composeTestRule.onNodeWithText("Show Canvas").performClick()
composeTestRule.onRoot().printToLog("RootNodeTree")
composeTestRule.onNodeWithText("Button was clicked").assertIsDisplayed()
Afzal Najam
10/07/2022, 5:39 PMwhile(true) { withFrameMillis { } }
a bad practice?
It seems like this has something to do with the coroutine cancellation policy.Zach Klippenstein (he/him) [MOD]
10/07/2022, 10:07 PMwithInfiniteAnimationFrameMillis
exists.
And yes, running an infinite animation without declaring it as such is a bad practice.
Espresso will not consider the main thread to be idle while anything has called withFrameMillis so if you call that in a loop, the thread will be “busy” as long as that loop is running.
withInfiniteAnimationFrameMillis
will immediately cancel the calling coroutine in UI tests to avoid keeping the main thread busy.