Skip to content

Commit aac59a6

Browse files
committed
fix: With KTor mock server, block until the start coroutine is done
1 parent 5c7c78b commit aac59a6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

consumer/src/main/kotlin/au/com/dius/pact/consumer/KTorMockServer.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import io.ktor.server.response.respondBytes
3232
import kotlinx.coroutines.CoroutineScope
3333
import kotlinx.coroutines.Dispatchers
3434
import kotlinx.coroutines.launch
35+
import kotlinx.coroutines.runBlocking
3536
import kotlinx.coroutines.withContext
3637
import java.net.URI
3738
import java.util.zip.DeflaterInputStream
@@ -163,14 +164,14 @@ class KTorMockServer @JvmOverloads constructor(
163164

164165
override fun start() {
165166
logger.debug { "Starting mock server" }
166-
167-
CoroutineScope(server.application.coroutineContext).launch {
168-
localAddress = server.engine.resolvedConnectors().first()
167+
runBlocking {
168+
val startJob = CoroutineScope(server.application.coroutineContext).launch {
169+
localAddress = server.engine.resolvedConnectors().first()
170+
}
171+
server.start()
172+
startJob.join()
173+
logger.debug { "Mock server started: $localAddress" }
169174
}
170-
171-
server.start()
172-
waitForServer()
173-
logger.debug { "Mock server started: $localAddress" }
174175
}
175176

176177
override fun stop() {

0 commit comments

Comments
 (0)