Skip to content

Commit 5965094

Browse files
committed
Add an integration test for coroutine debugger java agent
1 parent 3f9009d commit 5965094

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

integration-testing/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ The tests are the following:
99
`-PdryRun` affects `npmPublish` so that it only provides a packed publication
1010
and does not in fact attempt to send the build for publication.
1111
* `MavenPublicationValidator` depends on the published artifacts and tests artifacts binary content and absence of atomicfu in the classpath
12+
* `DebugAgentTest` checks that the coroutine debugger can be run as a Java agent.
1213

1314
All the available tests can be run with `integration-testing:test`.

integration-testing/build.gradle

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ sourceSets {
2020
compileClasspath += sourceSets.test.runtimeClasspath
2121
runtimeClasspath += sourceSets.test.runtimeClasspath
2222
}
23+
debugAgentTest {
24+
kotlin
25+
compileClasspath += sourceSets.test.runtimeClasspath
26+
runtimeClasspath += sourceSets.test.runtimeClasspath
27+
}
2328
}
2429

2530
task npmTest(type: Test) {
@@ -49,17 +54,27 @@ task mavenTest(type: Test) {
4954
project.dependencies.create("org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"))
5055
}
5156

57+
task debugAgentTest(type: Test) {
58+
def sourceSet = sourceSets.debugAgentTest
59+
dependsOn(project(':kotlinx-coroutines-debug').shadowJar)
60+
jvmArgs ('-javaagent:' + project(':kotlinx-coroutines-debug').shadowJar.outputs.files.getFiles()[0])
61+
testClassesDirs = sourceSet.output.classesDirs
62+
classpath = sourceSet.runtimeClasspath
63+
}
64+
5265
dependencies {
5366
testCompile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
5467
testCompile 'junit:junit:4.12'
5568
npmTestCompile 'org.apache.commons:commons-compress:1.18'
5669
npmTestCompile 'com.google.code.gson:gson:2.8.5'
70+
debugAgentTestCompile project(':kotlinx-coroutines-core')
71+
debugAgentTestCompile project(':kotlinx-coroutines-debug')
5772
}
5873

5974
compileTestKotlin {
6075
kotlinOptions.jvmTarget = "1.8"
6176
}
6277

6378
test {
64-
dependsOn([npmTest, mavenTest])
79+
dependsOn([npmTest, mavenTest, debugAgentTest])
6580
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
import org.junit.*
5+
import kotlinx.coroutines.*
6+
import kotlinx.coroutines.debug.*
7+
import java.io.*
8+
9+
class DebugAgentTest {
10+
11+
@Test
12+
fun agentDumpsCoroutines() = runBlocking {
13+
val baos = ByteArrayOutputStream()
14+
DebugProbes.dumpCoroutines(PrintStream(baos))
15+
// if the agent works, then dumps should contain something,
16+
// at least the fact that this test is running.
17+
Assert.assertTrue(baos.toString().contains("agentDumpsCoroutines"))
18+
}
19+
20+
}

0 commit comments

Comments
 (0)