-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Integration with BlockHound * Improve build configuration of integration tests * publication-validator is renamed to integration-testing; * Add an integration test for coroutine debugger java agent * Use JNA-based attach mechanism for dynamic attach Fixes #1821 Fixes #1060 Co-authored-by: Vsevolod Tolstopyatov <[email protected]> Co-authored-by: Sergei Egorov <[email protected]>
- Loading branch information
1 parent
df8316f
commit 02b403d
Showing
21 changed files
with
280 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Integration tests | ||
|
||
This is a supplementary subproject of kotlinx.coroutines that provides | ||
integration tests. | ||
|
||
The tests are the following: | ||
* `NpmPublicationValidator` tests that version of NPM artifact is correct and that it has neither source nor package dependencies on atomicfu | ||
In order for the test to work, one needs to run gradle with `-PdryRun=true`. | ||
`-PdryRun` affects `npmPublish` so that it only provides a packed publication | ||
and does not in fact attempt to send the build for publication. | ||
* `MavenPublicationValidator` depends on the published artifacts and tests artifacts binary content and absence of atomicfu in the classpath | ||
* `DebugAgentTest` checks that the coroutine debugger can be run as a Java agent. | ||
|
||
All the available tests can be run with `integration-testing:test`. |
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,80 @@ | ||
/* | ||
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
apply from: rootProject.file("gradle/compile-jvm.gradle") | ||
|
||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
|
||
sourceSets { | ||
npmTest { | ||
kotlin | ||
compileClasspath += sourceSets.test.runtimeClasspath | ||
runtimeClasspath += sourceSets.test.runtimeClasspath | ||
} | ||
mavenTest { | ||
kotlin | ||
compileClasspath += sourceSets.test.runtimeClasspath | ||
runtimeClasspath += sourceSets.test.runtimeClasspath | ||
} | ||
debugAgentTest { | ||
kotlin | ||
compileClasspath += sourceSets.test.runtimeClasspath | ||
runtimeClasspath += sourceSets.test.runtimeClasspath | ||
} | ||
} | ||
|
||
task npmTest(type: Test) { | ||
def sourceSet = sourceSets.npmTest | ||
environment "projectRoot", project.rootDir | ||
environment "deployVersion", version | ||
def dryRunNpm = project.properties['dryRun'] | ||
def doRun = dryRunNpm == "true" // so that we don't accidentally publish anything, especially before the test | ||
onlyIf { doRun } | ||
if (doRun) { // `onlyIf` only affects execution of the task, not the dependency subtree | ||
dependsOn(project(':').getTasksByName("publishNpm", true)) | ||
} | ||
testClassesDirs = sourceSet.output.classesDirs | ||
classpath = sourceSet.runtimeClasspath | ||
} | ||
|
||
task mavenTest(type: Test) { | ||
def sourceSet = sourceSets.mavenTest | ||
dependsOn(project(':').getTasksByName("publishToMavenLocal", true)) | ||
dependsOn.remove(project(':').getTasksByName("dokka", true)) | ||
testClassesDirs = sourceSet.output.classesDirs | ||
classpath = sourceSet.runtimeClasspath | ||
// we can't depend on the subprojects because we need to test the classfiles that are published in the end. | ||
// also, we can't put this in the `dependencies` block because the resolution would happen before publication. | ||
classpath += project.configurations.detachedConfiguration( | ||
project.dependencies.create("org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"), | ||
project.dependencies.create("org.jetbrains.kotlinx:kotlinx-coroutines-android:$version")) | ||
} | ||
|
||
task debugAgentTest(type: Test) { | ||
def sourceSet = sourceSets.debugAgentTest | ||
dependsOn(project(':kotlinx-coroutines-debug').shadowJar) | ||
jvmArgs ('-javaagent:' + project(':kotlinx-coroutines-debug').shadowJar.outputs.files.getFiles()[0]) | ||
testClassesDirs = sourceSet.output.classesDirs | ||
classpath = sourceSet.runtimeClasspath | ||
} | ||
|
||
dependencies { | ||
testCompile "org.jetbrains.kotlin:kotlin-stdlib-jdk8" | ||
testCompile 'junit:junit:4.12' | ||
npmTestCompile 'org.apache.commons:commons-compress:1.18' | ||
npmTestCompile 'com.google.code.gson:gson:2.8.5' | ||
debugAgentTestCompile project(':kotlinx-coroutines-core') | ||
debugAgentTestCompile project(':kotlinx-coroutines-debug') | ||
} | ||
|
||
compileTestKotlin { | ||
kotlinOptions.jvmTarget = "1.8" | ||
} | ||
|
||
test { | ||
dependsOn([npmTest, mavenTest, debugAgentTest]) | ||
} |
20 changes: 20 additions & 0 deletions
20
integration-testing/src/debugAgentTest/kotlin/DebugAgentTest.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,20 @@ | ||
/* | ||
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
import org.junit.* | ||
import kotlinx.coroutines.* | ||
import kotlinx.coroutines.debug.* | ||
import java.io.* | ||
|
||
class DebugAgentTest { | ||
|
||
@Test | ||
fun agentDumpsCoroutines() = runBlocking { | ||
val baos = ByteArrayOutputStream() | ||
DebugProbes.dumpCoroutines(PrintStream(baos)) | ||
// if the agent works, then dumps should contain something, | ||
// at least the fact that this test is running. | ||
Assert.assertTrue(baos.toString().contains("agentDumpsCoroutines")) | ||
} | ||
|
||
} |
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
File renamed without changes.
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
1 change: 1 addition & 0 deletions
1
...es-debug/resources/META-INF/services/reactor.blockhound.integration.BlockHoundIntegration
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 @@ | ||
kotlinx.coroutines.debug.CoroutinesBlockHoundIntegration |
16 changes: 16 additions & 0 deletions
16
kotlinx-coroutines-debug/src/CoroutinesBlockHoundIntegration.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,16 @@ | ||
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") | ||
package kotlinx.coroutines.debug | ||
|
||
import reactor.blockhound.BlockHound | ||
import kotlinx.coroutines.scheduling.* | ||
import reactor.blockhound.integration.* | ||
|
||
@Suppress("UNUSED") | ||
public class CoroutinesBlockHoundIntegration: BlockHoundIntegration { | ||
|
||
override fun applyTo(builder: BlockHound.Builder) { | ||
builder.addDynamicThreadPredicate { isSchedulerWorker(it) } | ||
builder.nonBlockingThreadPredicate { p -> p.or { mayNotBlock(it) } } | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package kotlinx.coroutines.debug | ||
import kotlinx.coroutines.* | ||
import org.junit.* | ||
import reactor.blockhound.* | ||
|
||
class BlockHoundTest : TestBase() { | ||
|
||
@Before | ||
fun init() { | ||
BlockHound.install() | ||
} | ||
|
||
@Test(expected = BlockingOperationError::class) | ||
fun shouldDetectBlockingInDefault() = runTest { | ||
withContext(Dispatchers.Default) { | ||
Thread.sleep(1) | ||
} | ||
} | ||
|
||
@Test | ||
fun shouldNotDetectBlockingInIO() = runTest { | ||
withContext(Dispatchers.IO) { | ||
Thread.sleep(1) | ||
} | ||
} | ||
|
||
@Test | ||
fun shouldNotDetectNonblocking() = runTest { | ||
withContext(Dispatchers.Default) { | ||
val a = 1 | ||
val b = 2 | ||
assert(a + b == 3) | ||
} | ||
} | ||
|
||
@Test | ||
fun testReusingThreads() = runTest { | ||
val n = 100 | ||
repeat(n) { | ||
async(Dispatchers.IO) { | ||
Thread.sleep(1) | ||
} | ||
} | ||
repeat(n) { | ||
async(Dispatchers.Default) { | ||
} | ||
} | ||
repeat(n) { | ||
async(Dispatchers.IO) { | ||
Thread.sleep(1) | ||
} | ||
} | ||
} | ||
|
||
@Test(expected = BlockingOperationError::class) | ||
fun testReusingThreadsFailure() = runTest { | ||
val n = 100 | ||
repeat(n) { | ||
async(Dispatchers.IO) { | ||
Thread.sleep(1) | ||
} | ||
} | ||
async(Dispatchers.Default) { | ||
Thread.sleep(1) | ||
} | ||
repeat(n) { | ||
async(Dispatchers.IO) { | ||
Thread.sleep(1) | ||
} | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.