Skip to content

Commit 838e599

Browse files
committed
Fix tests not being run with the right dispatcher
Integration with BlockHound revealed that several tests were performing blocking operations such as Thread.sleep in coroutine context `Dispatchers.DEFAULT`. Also, some tests hanged because the exception that notified about blocking calls were wildcard-matched.
1 parent 74008ae commit 838e599

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

kotlinx-coroutines-debug/test/CoroutinesDumpTest.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CoroutinesDumpTest : DebugTestBase() {
3939

4040
@Test
4141
fun testRunningCoroutine() = runBlocking {
42-
val deferred = async(Dispatchers.Default) {
42+
val deferred = async(Dispatchers.IO) {
4343
activeMethod(shouldSuspend = false)
4444
assertTrue(true)
4545
}
@@ -70,7 +70,7 @@ class CoroutinesDumpTest : DebugTestBase() {
7070

7171
@Test
7272
fun testRunningCoroutineWithSuspensionPoint() = runBlocking {
73-
val deferred = async(Dispatchers.Default) {
73+
val deferred = async(Dispatchers.IO) {
7474
activeMethod(shouldSuspend = true)
7575
yield() // tail-call
7676
}
@@ -100,7 +100,7 @@ class CoroutinesDumpTest : DebugTestBase() {
100100

101101
@Test
102102
fun testCreationStackTrace() = runBlocking {
103-
val deferred = async(Dispatchers.Default) {
103+
val deferred = async(Dispatchers.IO) {
104104
activeMethod(shouldSuspend = true)
105105
}
106106

@@ -129,7 +129,7 @@ class CoroutinesDumpTest : DebugTestBase() {
129129

130130
@Test
131131
fun testFinishedCoroutineRemoved() = runBlocking {
132-
val deferred = async(Dispatchers.Default) {
132+
val deferred = async(Dispatchers.IO) {
133133
activeMethod(shouldSuspend = true)
134134
}
135135

@@ -149,7 +149,10 @@ class CoroutinesDumpTest : DebugTestBase() {
149149
if (shouldSuspend) yield()
150150
notifyCoroutineStarted()
151151
while (coroutineContext[Job]!!.isActive) {
152-
runCatching { Thread.sleep(60_000) }
152+
try {
153+
Thread.sleep(60_000)
154+
} catch (_ : InterruptedException) {
155+
}
153156
}
154157
}
155158

kotlinx-coroutines-debug/test/RunningThreadStackMergeTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class RunningThreadStackMergeTest : DebugTestBase() {
133133
}
134134

135135
private fun CoroutineScope.launchEscapingCoroutineWithoutContext() {
136-
launch(Dispatchers.Default) {
136+
launch(Dispatchers.IO) {
137137
suspendingFunctionWithoutContext()
138138
assertTrue(true)
139139
}

0 commit comments

Comments
 (0)