Skip to content

Commit 26fab94

Browse files
authored
Fix flakiness of MainDispatcherTestBase.testWithTimeoutContextDelayTi… (#3970)
* Fix flakiness of MainDispatcherTestBase.testWithTimeoutContextDelayTimeout * On our virtualized Windows CI everything is slow and sub-seconds delays got racy on a regular basis, leading to flaky builds * Replace withContext(Dispatcher.Main) with launch(Dispatcher.Main, ATOMIC) {}.join() in order to avoid cancellation between dispatch and start race * An alternative way is to guard it with isJavaAndWindows that effectively disables such test on Windows
1 parent 85afa72 commit 26fab94

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

kotlinx-coroutines-core/common/test/MainDispatcherTestBase.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,14 @@ abstract class MainDispatcherTestBase: TestBase() {
211211
expect(1)
212212
assertFailsWith<TimeoutCancellationException> {
213213
withTimeout(300) {
214-
withContext(Dispatchers.Main) {
214+
// A substitute for withContext(Dispatcher.Main) that is started even if the 300ms
215+
// timeout happens fsater then dispatch
216+
launch(Dispatchers.Main, start = CoroutineStart.ATOMIC) {
215217
checkIsMainThread()
216218
expect(2)
217219
delay(1000)
218220
expectUnreached()
219-
}
221+
}.join()
220222
}
221223
expectUnreached()
222224
}

0 commit comments

Comments
 (0)