Emil Kantis
10/21/2021, 8:05 AMtest("client-server test") {
listOf(
async { client.sendRequest() }
async {
val req = server.takeRequest()
req.path shouldBe "/api/v1/hello"
}
).joinAll()
}
Richard Gomez
10/21/2021, 9:43 AMcoroutineScope
will wait for all child coroutines to complete before exiting;`async` is meant to be used with .await()
, so if you don't care about the return value you can just use launch
.
test("client-server test") {
coroutineScope {
launch { client.sendRequest() }
launch {
val req = server.takeRequest()
req.path shouldBe "/api/v1/hello"
}
}
}
Coroutines aren't necessarily the best fit if both sendRequest()
and takeRequest()
are blocking, but it may not matter for a test.Emil Kantis
10/21/2021, 1:20 PM