Sanitize thread names in tests to avoid intra-test interference
(coroutine name is removed from thread name)
diff --git a/kotlinx-coroutines-core/src/test/kotlin/guide/test/TestUtil.kt b/kotlinx-coroutines-core/src/test/kotlin/guide/test/TestUtil.kt
index 13de93a..01c1d20 100644
--- a/kotlinx-coroutines-core/src/test/kotlin/guide/test/TestUtil.kt
+++ b/kotlinx-coroutines-core/src/test/kotlin/guide/test/TestUtil.kt
@@ -43,11 +43,17 @@
}
val names = hashSetOf<String>()
for (i in 0 until n)
- names.add(arrayOfThreads[i]!!.name)
+ names.add(sanitizeThreadName(arrayOfThreads[i]!!.name))
return names
}
}
+// remove coroutine names from thread in case we have lost threads with coroutines running in them
+private fun sanitizeThreadName(name: String): String {
+ val i = name.indexOf(" @")
+ return if (i < 0) name else name.substring(0, i)
+}
+
fun checkTestThreads(threadNamesBefore: Set<String>) {
// give threads some time to shutdown
val waitTill = System.currentTimeMillis() + 1000L