Коммит 8e570d46 создал по автору dmitrievanthony's avatar dmitrievanthony Зафиксировано автором Leonid Stashevsky
Просмотр файлов

Fix OkHttp close method and correspondent test.

владелец b36ea958
...@@ -54,7 +54,7 @@ class OkHttpEngine( ...@@ -54,7 +54,7 @@ class OkHttpEngine(
clientTask.complete() clientTask.complete()
clientTask.invokeOnCompletion { clientTask.invokeOnCompletion {
launch(dispatcher) { GlobalScope.launch(dispatcher) {
engine.dispatcher().executorService().shutdown() engine.dispatcher().executorService().shutdown()
engine.connectionPool().evictAll() engine.connectionPool().evictAll()
engine.cache()?.close() engine.cache()?.close()
......
/*
* Copyright 2014-2019 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
package io.ktor.client.engine.okhttp
import kotlinx.coroutines.*
import okhttp3.*
import kotlin.test.*
class OkHttpEngineTests {
@Test
fun closeTest() {
val okHttpClient = OkHttpClient()
val engine = OkHttpEngine(OkHttpConfig().apply { preconfigured = okHttpClient })
engine.close()
runBlocking {
withTimeout(1000) {
while (!okHttpClient.dispatcher().executorService().isShutdown) {
yield()
}
assertTrue("OkHttp dispatcher is still working.") { okHttpClient.dispatcher().executorService().isShutdown }
assertEquals(0, okHttpClient.connectionPool().connectionCount())
okHttpClient.cache()?.let { assertTrue("OkHttp client cache is not closed.") { it.isClosed } }
}
}
}
}
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать