Skip to content

Commit

Permalink
Add an integration test for calling runBlocking from Java
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhalanskyjb committed Feb 28, 2025
1 parent 3f0a860 commit 0970c29
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
18 changes: 17 additions & 1 deletion integration-testing/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ sourceSets {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
}
}

create("javaConsumersTest") {
compileClasspath += sourceSets.test.get().runtimeClasspath
runtimeClasspath += sourceSets.test.get().runtimeClasspath

dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
}
}
}

kotlin {
Expand Down Expand Up @@ -199,16 +208,23 @@ tasks {
classpath = sourceSet.runtimeClasspath
}

create<Test>("javaConsumersTest") {
val sourceSet = sourceSets[name]
testClassesDirs = sourceSet.output.classesDirs
classpath = sourceSet.runtimeClasspath
}

check {
dependsOn(
"jvmCoreTest",
"debugDynamicAgentTest",
"mavenTest",
"debugAgentTest",
"coreAgentTest",
"javaConsumersTest",
":jpmsTest:check",
"smokeTest:build",
"java8Test:check"
"java8Test:check",
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import kotlinx.coroutines.BuildersKt;
import kotlinx.coroutines.Dispatchers;
import org.junit.Test;

public class RunBlockingJavaTest {
Boolean entered = false;

/** This code will not compile if `runBlocking` doesn't declare `@Throws(InterruptedException::class)` */
@Test
public void testRunBlocking() {
try {
BuildersKt.runBlocking(Dispatchers.getIO(), (scope, continuation) -> {
entered = true;
return null;
});
} catch (InterruptedException e) {
}
assert entered;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import kotlinx.coroutines.CoroutineScope

suspend fun CoroutineScope.asyncMain() {

}

0 comments on commit 0970c29

Please sign in to comment.