Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run wall-clock timeout in GlobalScope #168

Merged
merged 2 commits into from
Nov 3, 2022

Conversation

JakeWharton
Copy link
Member

This ensures its use of the Default dispatcher does not affect the use of a TestScheduler and its fake time.

Closes #164.

@JakeWharton
Copy link
Member Author

I only ran JVM tests locally, so... hope they pass!

@JakeWharton JakeWharton force-pushed the jw/timeout-on-global-scope/2022-11-03 branch from 00d16be to 4c22d44 Compare November 3, 2022 18:29
// Run the timeout on a scope separate from the caller. This ensures that the use of the
// Default dispatcher does not affect the use of a TestScheduler and its fake time.
@OptIn(DelicateCoroutinesApi::class)
val timeoutJob = GlobalScope.launch(Dispatchers.Default) { delay(timeout) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am surprised that this works

@jingibus
Copy link
Collaborator

jingibus commented Nov 3, 2022

Uncaught Kotlin exception: kotlin.IllegalStateException: There is no event loop. Use runBlocking { ... } to start one.

shakes fist JAVASCRIIIIIIPT

This uses the new memory manager by default.
This ensures its use of the Default dispatcher does not affect the use of a TestScheduler and its fake time.
@JakeWharton JakeWharton force-pushed the jw/timeout-on-global-scope/2022-11-03 branch from 4c22d44 to 3ab00b8 Compare November 3, 2022 19:06
@JakeWharton
Copy link
Member Author

Haha it's actually the Kotlin/Native tests which are breaking there and only the ones which run from a background thread. I ninja'd in a Kotlin 1.7.20 update commit which switches to the new memory model by default. This fixes the whole multithreaded coroutines saga once and for all (and makes the tests pass).

@JakeWharton JakeWharton merged commit 8295ee3 into trunk Nov 3, 2022
@JakeWharton JakeWharton deleted the jw/timeout-on-global-scope/2022-11-03 branch November 3, 2022 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can not control virtual time for multiple delay calls when using runTest
2 participants