anybody know how to set a custom test dispatcher o...
# ktor
e
anybody know how to set a custom test dispatcher on a MockEngine?
trying to upgrade to 3.1.2
that ticket was marked fixed in 3.0.0 so feels like it should be possible
tried doing this
Copy code
MockEngine { requestData: HttpRequestData ->
            val fakeResponse: FakeKtorResponse = fakeKtorHandlers.firstNotNullOfOrNull { it.invoke(requestData) }
                ?: FakeKtorResponse("", HttpStatusCode.NotFound)
            HttpResponseData(
                body = fakeResponse.content,
                statusCode = fakeResponse.statusCode,
                headers = headersOf(),
                requestTime = GMTDate(),
                version = HttpProtocolVersion.HTTP_1_1,
                callContext = testDispatcher, // SETTING IT HERE
            )
        }
but it blows up with
Current context doesn't contain Job in it:  StandardTestDispatcher[scheduler=kotlinx.coroutines.test.TestCoroutineScheduler@3d20e575]
got it!
had to switch to
MockEngine.create
and then you can set the
dispatcher
field on the config
Copy code
MockEngine.create {
            dispatcher = testDispatcher
            addHandler { requestData: HttpRequestData ->
                val fakeResponse: FakeKtorResponse = fakeKtorHandlers.firstNotNullOfOrNull { it.invoke(requestData) }
                    ?: FakeKtorResponse("", HttpStatusCode.NotFound)
                respond(
                    content = fakeResponse.content,
                    status = fakeResponse.statusCode,
                )
            }
        }