More predictable behaviour for example-channel-09 and better diagnostics on test failure
diff --git a/coroutines-guide.md b/coroutines-guide.md
index 6a16d6f..602e2a8 100644
--- a/coroutines-guide.md
+++ b/coroutines-guide.md
@@ -1513,7 +1513,7 @@
for (ball in table) { // receive the ball in a loop
ball.hits++
println("$name $ball")
- delay(200) // wait a bit
+ delay(300) // wait a bit
table.send(ball) // send the ball back
}
}
@@ -1531,7 +1531,6 @@
ping Ball(hits=3)
pong Ball(hits=4)
ping Ball(hits=5)
-pong Ball(hits=6)
```
<!--- TEST -->
diff --git a/kotlinx-coroutines-core/src/test/kotlin/guide/example-channel-09.kt b/kotlinx-coroutines-core/src/test/kotlin/guide/example-channel-09.kt
index c82fce4..2fdad2d 100644
--- a/kotlinx-coroutines-core/src/test/kotlin/guide/example-channel-09.kt
+++ b/kotlinx-coroutines-core/src/test/kotlin/guide/example-channel-09.kt
@@ -35,7 +35,7 @@
for (ball in table) { // receive the ball in a loop
ball.hits++
println("$name $ball")
- delay(200) // wait a bit
+ delay(300) // wait a bit
table.send(ball) // send the ball back
}
}
diff --git a/kotlinx-coroutines-core/src/test/kotlin/guide/test/GuideTest.kt b/kotlinx-coroutines-core/src/test/kotlin/guide/test/GuideTest.kt
index 58a4e43..5e4ac5c 100644
--- a/kotlinx-coroutines-core/src/test/kotlin/guide/test/GuideTest.kt
+++ b/kotlinx-coroutines-core/src/test/kotlin/guide/test/GuideTest.kt
@@ -341,8 +341,7 @@
"pong Ball(hits=2)",
"ping Ball(hits=3)",
"pong Ball(hits=4)",
- "ping Ball(hits=5)",
- "pong Ball(hits=6)"
+ "ping Ball(hits=5)"
)
}
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 0937bf7..28c5289 100644
--- a/kotlinx-coroutines-core/src/test/kotlin/guide/test/TestUtil.kt
+++ b/kotlinx-coroutines-core/src/test/kotlin/guide/test/TestUtil.kt
@@ -99,9 +99,16 @@
}
}
+private fun List<String>.checkEqualNumberOfLines(expected: Array<out String>) {
+ if (size > expected.size)
+ error("Expected ${expected.size} lines, but found $size. Unexpected line '${get(expected.size)}'")
+ else if (size < expected.size)
+ error("Expected ${expected.size} lines, but found $size")
+}
+
fun List<String>.verifyLines(vararg expected: String) {
verifyCommonLines(expected)
- assertEquals("Number of lines", expected.size, size)
+ checkEqualNumberOfLines(expected)
}
fun List<String>.verifyLinesStartWith(vararg expected: String) {
@@ -111,17 +118,17 @@
fun List<String>.verifyLinesArbitraryTime(vararg expected: String) {
verifyCommonLines(expected, SanitizeMode.ARBITRARY_TIME)
- assertEquals("Number of lines", expected.size, size)
+ checkEqualNumberOfLines(expected)
}
fun List<String>.verifyLinesFlexibleTime(vararg expected: String) {
verifyCommonLines(expected, SanitizeMode.FLEXIBLE_TIME)
- assertEquals("Number of lines", expected.size, size)
+ checkEqualNumberOfLines(expected)
}
fun List<String>.verifyLinesFlexibleThread(vararg expected: String) {
verifyCommonLines(expected, SanitizeMode.FLEXIBLE_THREAD)
- assertEquals("Number of lines", expected.size, size)
+ checkEqualNumberOfLines(expected)
}
fun List<String>.verifyLinesStartUnordered(vararg expected: String) {
@@ -136,5 +143,5 @@
val act = sanitize(get(i), SanitizeMode.FLEXIBLE_THREAD)
assertEquals("Line ${i + 1}", exp, act.substring(0, minOf(act.length, exp.length)))
}
- assertEquals("Number of lines", expected.size, size)
+ checkEqualNumberOfLines(expected)
}
\ No newline at end of file