Skip to content

Commit 57254ab

Browse files
committed
Add an integration test for calling runBlocking from Java
1 parent 3f0a860 commit 57254ab

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

integration-testing/build.gradle.kts

+17-1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ sourceSets {
134134
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
135135
}
136136
}
137+
138+
create("javaConsumersTest") {
139+
compileClasspath += sourceSets.test.get().runtimeClasspath
140+
runtimeClasspath += sourceSets.test.get().runtimeClasspath
141+
142+
dependencies {
143+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
144+
}
145+
}
137146
}
138147

139148
kotlin {
@@ -199,16 +208,23 @@ tasks {
199208
classpath = sourceSet.runtimeClasspath
200209
}
201210

211+
create<Test>("javaConsumersTest") {
212+
val sourceSet = sourceSets[name]
213+
testClassesDirs = sourceSet.output.classesDirs
214+
classpath = sourceSet.runtimeClasspath
215+
}
216+
202217
check {
203218
dependsOn(
204219
"jvmCoreTest",
205220
"debugDynamicAgentTest",
206221
"mavenTest",
207222
"debugAgentTest",
208223
"coreAgentTest",
224+
"javaConsumersTest",
209225
":jpmsTest:check",
210226
"smokeTest:build",
211-
"java8Test:check"
227+
"java8Test:check",
212228
)
213229
}
214230

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import kotlinx.coroutines.BuildersKt;
2+
import kotlinx.coroutines.Dispatchers;
3+
import org.junit.Test;
4+
5+
public class RunBlockingJavaTest {
6+
Boolean entered = false;
7+
8+
/** This code will not compile if `runBlocking` doesn't declare `@Throws(InterruptedException::class)` */
9+
@Test
10+
public void testRunBlocking() {
11+
try {
12+
BuildersKt.runBlocking(Dispatchers.getIO(), (scope, continuation) -> {
13+
entered = true;
14+
return null;
15+
});
16+
} catch (InterruptedException e) {
17+
}
18+
assert entered;
19+
}
20+
}

0 commit comments

Comments
 (0)