Skip to content

Commit d26a8c8

Browse files
committed
Avoid using Java9+ APIs in JUnit5 CoroutineTimeout
Fixes #4278
1 parent be5be56 commit d26a8c8

File tree

7 files changed

+47
-7
lines changed

7 files changed

+47
-7
lines changed

integration-testing/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ compileTestKotlin {
167167
}
168168

169169
check {
170-
dependsOn([jvmCoreTest, debugDynamicAgentTest, mavenTest, debugAgentTest, coreAgentTest, ":jpmsTest:check", 'smokeTest:build'])
170+
dependsOn([jvmCoreTest, debugDynamicAgentTest, mavenTest, debugAgentTest, coreAgentTest, ":jpmsTest:check", 'smokeTest:build', "java8Test:check"])
171171
}
172172
compileKotlin {
173173
kotlinOptions {

integration-testing/gradle.properties

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
kotlin_version=2.0.0
22
coroutines_version=1.9.0-SNAPSHOT
33
asm_version=9.3
4+
junit5_version=5.7.0
45

56
kotlin.code.style=official
67
kotlin.mpp.stability.nowarn=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
plugins {
2+
kotlin("jvm")
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
8+
// Coroutines from the outer project are published by previous CI buils step
9+
mavenLocal()
10+
}
11+
12+
tasks.test {
13+
useJUnitPlatform()
14+
}
15+
16+
val coroutinesVersion = property("coroutines_version")
17+
val junit5Version = property("junit5_version")
18+
19+
kotlin {
20+
jvmToolchain(8)
21+
dependencies {
22+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-debug:$coroutinesVersion")
23+
testImplementation("org.junit.jupiter:junit-jupiter-engine:$junit5Version")
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import kotlinx.coroutines.debug.junit5.CoroutinesTimeout
2+
import org.junit.jupiter.api.*
3+
4+
class JUnit5TimeoutCompilation {
5+
@CoroutinesTimeout(10)
6+
@Test
7+
fun test() {
8+
}
9+
}

integration-testing/settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pluginManagement {
88
}
99

1010
include 'smokeTest'
11+
include 'java8Test'
1112
include(":jpmsTest")
1213

1314
rootProject.name = "kotlinx-coroutines-integration-testing"

integration-testing/smokeTest/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ kotlin {
1818
nodejs()
1919
}
2020

21-
macosArm64()
22-
macosX64()
21+
// macosArm64()
22+
// macosX64()
2323
linuxArm64()
2424
linuxX64()
2525
mingwX64()
@@ -76,4 +76,4 @@ rootProject.extensions.findByType(org.jetbrains.kotlin.gradle.targets.js.nodejs.
7676
// canary nodejs that supports recent Wasm GC changes
7777
it.nodeVersion = "21.0.0-v8-canary202309167e82ab1fa2"
7878
it.nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
79-
}
79+
}

kotlinx-coroutines-debug/src/junit/junit5/CoroutinesTimeoutExtension.kt

+7-3
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,12 @@ internal class CoroutinesTimeoutExtension internal constructor(
206206
}
207207

208208
private fun<T> Class<T>.coroutinesTimeoutAnnotation(): Optional<CoroutinesTimeout> =
209-
AnnotationSupport.findAnnotation(this, CoroutinesTimeout::class.java).or {
210-
enclosingClass?.coroutinesTimeoutAnnotation() ?: Optional.empty()
209+
AnnotationSupport.findAnnotation(this, CoroutinesTimeout::class.java).let {
210+
when {
211+
it.isPresent -> it
212+
enclosingClass != null -> enclosingClass.coroutinesTimeoutAnnotation()
213+
else -> Optional.empty()
214+
}
211215
}
212216

213217
private fun <T: Any?> interceptMethod(
@@ -232,7 +236,7 @@ internal class CoroutinesTimeoutExtension internal constructor(
232236
}
233237
/* The extension was registered via an annotation; check that we succeeded in finding the annotation that led to
234238
the extension being registered and taking its parameters. */
235-
if (testAnnotationOptional.isEmpty && classAnnotationOptional.isEmpty) {
239+
if (!testAnnotationOptional.isPresent && !classAnnotationOptional.isPresent) {
236240
throw UnsupportedOperationException("Timeout was registered with a CoroutinesTimeout annotation, but we were unable to find it. Please report this.")
237241
}
238242
return when {

0 commit comments

Comments
 (0)