https://kotlinlang.org logo
#kotest
Title
# kotest
e

Emil Kantis

10/21/2021, 8:05 AM
Is there any more convenient pattern for invoking two blocking things that depend on each other than doing the following?
Copy code
test("client-server test") {
  listOf(
    async { client.sendRequest() }
    async { 
      val req = server.takeRequest()
      req.path shouldBe "/api/v1/hello"
    }
  ).joinAll()
}
r

Richard Gomez

10/21/2021, 9:43 AM
I would personally do something like below.
coroutineScope
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
.
Copy code
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.
e

Emil Kantis

10/21/2021, 1:20 PM
will try that, thx 🙂
3 Views