-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not track coroutines with empty coroutine context in DebugProbes (#…
…3784) Such coroutines typically are a subject for significant debugger overhead, can be observed with more conventional tools, and do not contribute to the state of the system that is typically observed with coroutines debugger Fixes #3782 Co-authored-by: Oleg Yukhnevich <[email protected]> Co-authored-by: Dmitry Khalanskiy <[email protected]>
- Loading branch information
1 parent
5664713
commit d4f45b6
Showing
6 changed files
with
134 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
kotlinx-coroutines-debug/test/StandardBuildersDebugTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
package kotlinx.coroutines.debug | ||
|
||
import org.junit.Test | ||
import kotlin.test.* | ||
|
||
class StandardBuildersDebugTest : DebugTestBase() { | ||
|
||
@Test | ||
fun testBuildersAreMissingFromDumpByDefault() = runTest { | ||
val (b1, b2) = createBuilders() | ||
|
||
val coroutines = DebugProbes.dumpCoroutinesInfo() | ||
assertEquals(1, coroutines.size) | ||
assertTrue { b1.hasNext() && b2.hasNext() } // Don't let GC collect our coroutines until the test is complete | ||
} | ||
|
||
@Test | ||
fun testBuildersCanBeEnabled() = runTest { | ||
try { | ||
DebugProbes.ignoreCoroutinesWithEmptyContext = false | ||
val (b1, b2) = createBuilders() | ||
val coroutines = DebugProbes.dumpCoroutinesInfo() | ||
assertEquals(3, coroutines.size) | ||
assertTrue { b1.hasNext() && b2.hasNext() } // Don't let GC collect our coroutines until the test is complete | ||
} finally { | ||
DebugProbes.ignoreCoroutinesWithEmptyContext = true | ||
} | ||
} | ||
|
||
private fun createBuilders(): Pair<Iterator<Int>, Iterator<Int>> { | ||
val fromSequence = sequence { | ||
while (true) { | ||
yield(1) | ||
} | ||
}.iterator() | ||
|
||
val fromIterator = iterator { | ||
while (true) { | ||
yield(1) | ||
} | ||
} | ||
// Start coroutines | ||
fromIterator.hasNext() | ||
fromSequence.hasNext() | ||
return fromSequence to fromIterator | ||
} | ||
} |