Skip to content

Commit

Permalink
Run timeout tests via Gradle test task so they can be retried
Browse files Browse the repository at this point in the history
Since some of these tests occasionally fail on CI, in particular on
Windows, they are now run via Gradle so that they are retried on CI
automatically and reported as flaky rather than failing the build.
  • Loading branch information
marcphilipp committed Feb 21, 2023
1 parent e0e8778 commit 4e64cf2
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 6 deletions.
14 changes: 11 additions & 3 deletions documentation/documentation.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ plugins {
id("org.asciidoctor.jvm.pdf")
id("org.ajoberstar.git-publish")
id("junitbuild.kotlin-library-conventions")
id("junitbuild.testing-conventions")
}

val modularProjects: List<Project> by rootProject
Expand All @@ -37,7 +38,6 @@ dependencies {
// in reports generated by the ApiReportGenerator.
modularProjects.forEach { apiReport(it) }

testImplementation(projects.junitJupiter)
testImplementation(projects.junitJupiterMigrationsupport)
testImplementation(projects.junitPlatformConsole)
testImplementation(projects.junitPlatformRunner)
Expand All @@ -46,7 +46,6 @@ dependencies {
testImplementation(kotlin("stdlib"))

testImplementation(projects.junitVintageEngine)
testRuntimeOnly(libs.bundles.log4j)
testRuntimeOnly(libs.apiguardian) {
because("it's required to generate API tables")
}
Expand Down Expand Up @@ -121,6 +120,7 @@ tasks {
args.addAll("--include-classname", ".*Tests")
args.addAll("--include-classname", ".*Demo")
args.addAll("--exclude-tag", "exclude")
args.addAll("--exclude-tag", "timeout")
}

register<RunConsoleLauncher>("consoleLauncher") {
Expand All @@ -131,11 +131,19 @@ tasks {
args.addAll("--include-classname", ".*Tests")
args.addAll("--include-classname", ".*Demo")
args.addAll("--exclude-tag", "exclude")
args.addAll("--exclude-tag", "timeout")
}

test {
include("**/*Demo.class")
(options as JUnitPlatformOptions).apply {
includeEngines("junit-vintage")
includeTags("timeout")
}
}

check {
dependsOn(consoleLauncherTest)
exclude("**/*")
}

val generateConsoleLauncherOptions by registering(JavaExec::class) {
Expand Down
12 changes: 12 additions & 0 deletions documentation/src/test/java/example/AssertionsDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import example.domain.Person;
import example.util.Calculator;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

class AssertionsDemo {
Expand Down Expand Up @@ -91,6 +92,9 @@ void exceptionTesting() {
assertEquals("/ by zero", exception.getMessage());
}

// end::user_guide[]
@Tag("timeout")
// tag::user_guide[]
@Test
void timeoutNotExceeded() {
// The following assertion succeeds.
Expand All @@ -99,6 +103,9 @@ void timeoutNotExceeded() {
});
}

// end::user_guide[]
@Tag("timeout")
// tag::user_guide[]
@Test
void timeoutNotExceededWithResult() {
// The following assertion succeeds, and returns the supplied object.
Expand All @@ -108,6 +115,9 @@ void timeoutNotExceededWithResult() {
assertEquals("a result", actualResult);
}

// end::user_guide[]
@Tag("timeout")
// tag::user_guide[]
@Test
void timeoutNotExceededWithMethod() {
// The following assertion invokes a method reference and returns an object.
Expand All @@ -116,6 +126,7 @@ void timeoutNotExceededWithMethod() {
}

// end::user_guide[]
@Tag("timeout")
@extensions.ExpectToFail
// tag::user_guide[]
@Test
Expand All @@ -129,6 +140,7 @@ void timeoutExceeded() {
}

// end::user_guide[]
@Tag("timeout")
@extensions.ExpectToFail
// tag::user_guide[]
@Test
Expand Down
4 changes: 2 additions & 2 deletions documentation/src/test/java/example/SlowTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@

package example;

// tag::user_guide[]
import static org.junit.jupiter.api.parallel.ExecutionMode.SAME_THREAD;

import java.util.stream.IntStream;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;

@Tag("exclude")
@Disabled
class SlowTests {

Expand Down Expand Up @@ -123,4 +124,3 @@ private void foo() {
IntStream.range(1, 100_000_000).mapToDouble(i -> Math.pow(i, i)).map(Math::sqrt).max();
}
}
// end::user_guide[]
2 changes: 2 additions & 0 deletions documentation/src/test/java/example/TimeoutDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.Timeout.ThreadMode;

@Tag("timeout")
// tag::user_guide[]
class TimeoutDemo {

Expand Down
5 changes: 5 additions & 0 deletions documentation/src/test/kotlin/example/KotlinAssertionsDemo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import example.domain.Person
import example.util.Calculator
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertAll
import org.junit.jupiter.api.assertDoesNotThrow
Expand Down Expand Up @@ -76,6 +77,9 @@ class KotlinAssertionsDemo {
)
}

// end::user_guide[]
@Tag("timeout")
// tag::user_guide[]
@Test
fun `timeout not exceeded testing`() {
val fibonacciCalculator = FibonacciCalculator()
Expand All @@ -86,6 +90,7 @@ class KotlinAssertionsDemo {
}

// end::user_guide[]
@Tag("timeout")
@extensions.ExpectToFail
// tag::user_guide[]
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ dependencies {
if (!project.name.startsWith("junit-jupiter")) {
testImplementation(project(":junit-jupiter"))
}
testImplementation(testFixtures(project(":junit-jupiter-api")))

testRuntimeOnly(project(":junit-platform-engine"))
testRuntimeOnly(project(":junit-platform-jfr"))
Expand Down
1 change: 1 addition & 0 deletions junit-jupiter-engine/junit-jupiter-engine.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
testImplementation(libs.junit4)
testImplementation(libs.kotlinx.coroutines)
testImplementation(libs.groovy4)
testImplementation(testFixtures(projects.junitJupiterApi))

osgiVerification(projects.junitPlatformLauncher)
}
Expand Down
1 change: 1 addition & 0 deletions junit-vintage-engine/junit-vintage-engine.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
testImplementation(projects.junitPlatformLauncher)
testImplementation(projects.junitPlatformSuiteEngine)
testImplementation(projects.junitPlatformTestkit)
testImplementation(testFixtures(projects.junitJupiterApi))

osgiVerification(projects.junitPlatformLauncher)
}
Expand Down
1 change: 1 addition & 0 deletions platform-tests/platform-tests.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {
testImplementation(libs.joox)
testImplementation(libs.openTestReporting.tooling)
testImplementation(libs.bundles.xmlunit)
testImplementation(testFixtures(projects.junitJupiterApi))

// --- Test run-time dependencies ---------------------------------------------
testRuntimeOnly(projects.junitVintageEngine)
Expand Down

0 comments on commit 4e64cf2

Please sign in to comment.