Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BlockHound integration #1821

Merged
merged 15 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
dkhalanskyjb committed Mar 13, 2020
commit 69f76dc332b40ca20e61636967558505b0b81d2b
13 changes: 8 additions & 5 deletions kotlinx-coroutines-debug/test/CoroutinesDumpTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CoroutinesDumpTest : DebugTestBase() {

@Test
fun testRunningCoroutine() = runBlocking {
val deferred = async(Dispatchers.Default) {
val deferred = async(Dispatchers.IO) {
activeMethod(shouldSuspend = false)
assertTrue(true)
}
Expand Down Expand Up @@ -70,7 +70,7 @@ class CoroutinesDumpTest : DebugTestBase() {

@Test
fun testRunningCoroutineWithSuspensionPoint() = runBlocking {
val deferred = async(Dispatchers.Default) {
val deferred = async(Dispatchers.IO) {
activeMethod(shouldSuspend = true)
yield() // tail-call
}
Expand Down Expand Up @@ -100,7 +100,7 @@ class CoroutinesDumpTest : DebugTestBase() {

@Test
fun testCreationStackTrace() = runBlocking {
val deferred = async(Dispatchers.Default) {
val deferred = async(Dispatchers.IO) {
activeMethod(shouldSuspend = true)
}

Expand Down Expand Up @@ -129,7 +129,7 @@ class CoroutinesDumpTest : DebugTestBase() {

@Test
fun testFinishedCoroutineRemoved() = runBlocking {
val deferred = async(Dispatchers.Default) {
val deferred = async(Dispatchers.IO) {
activeMethod(shouldSuspend = true)
}

Expand All @@ -149,7 +149,10 @@ class CoroutinesDumpTest : DebugTestBase() {
if (shouldSuspend) yield()
notifyCoroutineStarted()
while (coroutineContext[Job]!!.isActive) {
runCatching { Thread.sleep(60_000) }
try {
Thread.sleep(60_000)
} catch (_ : InterruptedException) {
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class RunningThreadStackMergeTest : DebugTestBase() {
}

private fun CoroutineScope.launchEscapingCoroutineWithoutContext() {
launch(Dispatchers.Default) {
launch(Dispatchers.IO) {
suspendingFunctionWithoutContext()
assertTrue(true)
}
Expand Down