sanggggg
03/28/2023, 3:18 AMsanggggg
03/28/2023, 3:18 AMfire and forget
kind of way in production code, but in a test code I want to make sure that these side effects have been successfully terminated.sanggggg
03/28/2023, 3:21 AMList<Deferred>
of side effects because my actual usage requires me to create an endpoint and test it e2e via spring framework.jw
03/28/2023, 3:21 AM.join
on the Job
jw
03/28/2023, 3:22 AMjw
03/28/2023, 3:22 AMcoroutineScope { endpoint(this) }
and then you're donejw
03/28/2023, 3:23 AMsanggggg
03/28/2023, 3:27 AMAnother thing you can do, though, is just useThis is what I wanted most, but since the call to the endpoint is actually through the spring framework, it is difficult to pass the coroutineScope or context, so I was looking for a way to pass the coroutineScope as a function argument (it do not support that kind of coroutine e2e testings...).and then you’re donecoroutineScope { endpoint(this) }
CallI think this is working in my codes, I will try this in my codes! Thank you for kind answers blob smile happyon the.join
Job
Jilles van Gurp
03/28/2023, 8:56 AMfun runTest(wait: Duration = 120.seconds, context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> Unit) {
runBlocking(context) {
try {
withTimeout(wait, block)
} catch (e: TimeoutCancellationException) {
throw IllegalStateException("test timed out after ${wait}", e)
}
}
}
2. We put assertions in an eventually
block (comes with kotest assertions). So we can simply assert something should have happened and it will just poll until that becomes true or the test times out. Great for testing asynchronous side effects.Jilles van Gurp
03/28/2023, 8:57 AMfun shouldTest() = runTest {
...
eventually {
}
...
}