https://kotlinlang.org logo
#ktor
Title
# ktor
g

gotoOla

01/29/2020, 9:03 AM
@e5l I stumbled on a file where you have done some work https://github.com/ktorio/ktor/blob/master/ktor-client/ktor-client-mock/jvm/test/io/ktor/client/tests/mock/MockEngineExtendedTests.kt 🙂 Do you happen to know if the MockEngine is thread safe? I'm seeing some flaky test where I fire of 10 concurrent requests towards the a mocked httpClient
Copy code
mockEngineConfig.addHandler { request ->
    respondOk()
}
ktorMockEngine = MockEngine(mockEngineConfig)
val httpClient = HttpClient(ktorMockEngine)

// fire off 10 concurrent requests, ackording to the logs all of them are sent but I end up with
Assertions.assertThat(ktorMockEngine.requestHistory.size).isEqualTo(10)
Expecting:
 <8>
to be equal to:
 <10>
actually I every now and then see this in the logs:
Copy code
10:00:09.259 [DefaultDispatcher-worker-8 @coroutine#8] ERROR c.m.o.s.core.sqs.SqsMessagePipeline - Unable to process message with id: '3'.
java.lang.IllegalStateException: Unhandled <http://localhost:8081/query>
	at io.ktor.client.engine.mock.MockEngine.execute(MockEngine.kt:44)
Do I need to wait for the MockEngine to get initialized? Is there anyway I can check if that is ready?
2 Views