@Test
fun testProduceState() {
var inputState by mutableStateOf(true)
rule.setContent {
val outputState by produceState(initialValue = false, inputState) {
value = async(Dispatchers.Default) {
delay(100)
!inputState
}.await()
}
Text("$outputState")
}
rule.onNodeWithText("false").assertExists()
inputState = false
rule.onNodeWithText("true").assertExists()
}
Alexander Maryanovsky
01/20/2024, 1:41 PM
It seems the test framework thinks the system is “idle” while produceState is still waiting for the computation.
z
Zach Klippenstein (he/him) [MOD]
01/20/2024, 6:49 PM
I believe it’s because the test framework has no way to know what’s going on on the default dispatcher. As far as compose and even android/espresso are concerned, the main thread is idle. There happens to be some background thread that’s sleeping, but that’s not part of the idle criteria.