chrisjenx
02/21/2025, 5:05 PMAlexander Maryanovsky
02/21/2025, 6:15 PMsleep
, at least on the desktop. But other than spinning the CPU unnecessarily, why does it matter? sleep
also blocks the thread.chrisjenx
02/21/2025, 6:16 PMchrisjenx
02/21/2025, 6:16 PMAlexander Maryanovsky
02/21/2025, 6:16 PMAlexander Maryanovsky
02/21/2025, 6:16 PMchrisjenx
02/21/2025, 6:17 PMwaitUntil
doesn't...Alexander Maryanovsky
02/21/2025, 6:18 PM@Test
fun myTest() = runComposeUiTest {
setContent {}
waitUntil(
timeoutMillis = 1_000,
condition = { false }
)
}
fails after 1 second with
Condition still not satisfied after 1000 ms
androidx.compose.ui.test.ComposeTimeoutException: Condition still not satisfied after 1000 ms
chrisjenx
02/21/2025, 6:18 PMAlexander Maryanovsky
02/21/2025, 6:19 PMvar value = false
@Test
fun myTest() = runComposeUiTest {
thread {
Thread.sleep(1000)
value = true
}
setContent {}
waitUntil(
timeoutMillis = 2_000,
condition = { value }
)
}
passes after 1 secondchrisjenx
02/21/2025, 6:20 PMAlexander Maryanovsky
02/21/2025, 6:20 PMsleep
won’t solve thatchrisjenx
02/21/2025, 6:20 PMchrisjenx
02/21/2025, 6:20 PMchrisjenx
02/21/2025, 6:21 PMAlexander Maryanovsky
02/21/2025, 6:21 PMchrisjenx
02/21/2025, 6:42 PMchrisjenx
02/21/2025, 6:44 PMAlexander Maryanovsky
02/21/2025, 6:54 PMchrisjenx
02/21/2025, 6:57 PMAlexander Maryanovsky
02/21/2025, 6:58 PMchrisjenx
03/24/2025, 7:22 PMAlexander Maryanovsky
03/24/2025, 7:24 PMchrisjenx
03/24/2025, 7:25 PM// Let Android run measure, draw and in general any other async operations.
Thread.sleep(10)
chrisjenx
03/24/2025, 7:25 PMany other async operations.
chrisjenx
03/24/2025, 7:26 PMchrisjenx
03/24/2025, 7:26 PMchrisjenx
03/24/2025, 7:27 PMAlexander Maryanovsky
03/24/2025, 7:35 PMWhy is the desktop implementation different?Because the implementation is allowed to be different, if the effect is the same. Many things are implemented differently in compose-multiplatform. The reason here specifically is that you’re not looking at desktop/JVM code, but pure Kotlin (multiplatform) code, and there’s no
sleep
function in Kotlin.
We could add an expect/actual and actually sleep
in the desktop implementation, if there’s a good reason to do so.
after them showing you multiple issues doesn’t get us anywhere
After there are multiple people and tickets presenting this issueYou have linked one unrelated issue here.
Alexander Maryanovsky
03/24/2025, 7:35 PMchrisjenx
03/24/2025, 7:38 PMchrisjenx
03/24/2025, 7:38 PMchrisjenx
03/24/2025, 7:41 PMAlexander Maryanovsky
03/24/2025, 8:14 PMsleep
would make a difference here is if what you’re waiting until happens in a thread with a much lower priority, and the scheduler never actually runs it. I don’t know if any JVMs have such a scheduler.Alexander Maryanovsky
03/24/2025, 8:17 PMsleep
does help you, you can use something like this:
@OptIn(ExperimentalTestApi::class)
inline fun ComposeUiTest.waitUntilIdleWithSleep(
conditionDescription: String? = null,
timeoutMillis: Long,
crossinline condition: () -> Boolean
) {
waitUntil(
conditionDescription,
timeoutMillis,
condition = {
condition().also {
Thread.sleep(10)
}
}
)
}
chrisjenx
03/24/2025, 8:26 PMchrisjenx
03/24/2025, 8:32 PMAlexander Maryanovsky
03/24/2025, 8:36 PMthrow ComposeTimeoutException
there, which was fixed herechrisjenx
03/24/2025, 8:40 PMchrisjenx
03/24/2025, 8:46 PM