Skip to content

Commit

Permalink
Fix report for multiple failed engines in native
Browse files Browse the repository at this point in the history
  • Loading branch information
e5l committed Aug 17, 2020
1 parent df20c20 commit 5c81e0b
Showing 1 changed file with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ package io.ktor.client.tests.utils
import io.ktor.client.engine.*
import kotlinx.coroutines.*


private class TestFailure(val name: String, val cause: Throwable) {
override fun toString(): String = buildString {
appendln("Test failed with engine: $name")
appendln(cause)
for (stackline in cause.getStackTrace()) {
appendln("\t$stackline")
}
}
}

/**
* Helper interface to test client.
*/
Expand All @@ -19,15 +30,28 @@ actual abstract class ClientLoader {
block: suspend TestClientBuilder<HttpClientEngineConfig>.() -> Unit
) {
val skipEnginesLowerCase = skipEngines.map { it.toLowerCase() }
engines
.filter { !skipEnginesLowerCase.contains(it.toString().toLowerCase()) }
.forEach {
testWithEngine(it) {
val filteredEngines = engines.filter { !skipEnginesLowerCase.contains(it.toString().toLowerCase()) }

val failures = mutableListOf<TestFailure>()
for (engine in filteredEngines) {
val result = runCatching {
testWithEngine(engine) {
withTimeout(3000) {
block()
}
}
}

if (result.isFailure) {
failures += TestFailure(engine.toString(), result.exceptionOrNull()!!)
}
}

if (failures.isEmpty()) {
return
}

error(failures.joinToString("\n"))
}

actual fun dumpCoroutines() {
Expand Down

0 comments on commit 5c81e0b

Please sign in to comment.