Skip to content

Commit 2d9d4ac

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

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
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+
}

kotlinx-coroutines-core/jvm/test-resources/stacktraces/channels/testSendToChannel.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ Caused by: java.util.concurrent.CancellationException: Channel was cancelled
1717
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt)
1818
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlockingImpl(Builders.kt)
1919
at kotlinx.coroutines.BuildersKt.runBlockingImpl(Unknown Source)
20-
at kotlinx.coroutines.BuildersKt__Builders_concurrentKt.runBlocking(Builders.concurrent.kt)
21-
at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
20+
at kotlinx.coroutines.Builders_concurrentKt.runBlocking(Builders.concurrent.kt)
2221
at kotlinx.coroutines.testing.TestBase.runTest(TestBase.kt)

0 commit comments

Comments
 (0)