From 92c5768ceec3b4b94091dd95e8627524ef9fce03 Mon Sep 17 00:00:00 2001 From: Hunter Mellema <124718352+hpmellema@users.noreply.github.com> Date: Mon, 28 Aug 2023 08:29:16 -0600 Subject: [PATCH] Fix flaky init cache unit tests (#1956) --- build.gradle | 7 ++++--- smithy-cli/build.gradle | 9 +++++++-- .../software/amazon/smithy/cli/CleanCommandTest.java | 4 ++-- .../java/software/amazon/smithy/cli/InitCommandTest.java | 2 ++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index dd79739ce27..2e7c14a3f76 100644 --- a/build.gradle +++ b/build.gradle @@ -53,10 +53,11 @@ subprojects { } dependencies { - testImplementation "org.junit.jupiter:junit-jupiter-api:5.4.0" - testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.4.0" - testImplementation "org.junit.jupiter:junit-jupiter-params:5.4.0" + testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.0" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.0" + testImplementation "org.junit.jupiter:junit-jupiter-params:5.10.0" testImplementation "org.hamcrest:hamcrest:2.1" + testCompileOnly "org.apiguardian:apiguardian-api:1.1.2" } // Reusable license copySpec for building JARs diff --git a/smithy-cli/build.gradle b/smithy-cli/build.gradle index df4bd77d0ca..dcfb805adb7 100644 --- a/smithy-cli/build.gradle +++ b/smithy-cli/build.gradle @@ -57,6 +57,7 @@ dependencies { implementation "org.slf4j:slf4j-jdk14:1.7.36" // Route slf4j used by Maven through JUL like the rest of Smithy. testImplementation "org.mock-server:mockserver-netty:3.10.8" + } // ------ Shade Maven dependency resolvers into the JAR. ------- @@ -223,7 +224,7 @@ tasks["runtime"].dependsOn("shadowJar") sourceSets { create("it") { - compileClasspath += sourceSets["main"].output + configurations["testRuntimeClasspath"] + compileClasspath += sourceSets["main"].output + configurations["testRuntimeClasspath"] + configurations["testCompileClasspath"] runtimeClasspath += output + compileClasspath + sourceSets["test"].runtimeClasspath } } @@ -233,7 +234,11 @@ task integ(type: Test) { systemProperty "SMITHY_BINARY", "${smithyBinary}" testClassesDirs = sourceSets["it"].output.classesDirs classpath = sourceSets["it"].runtimeClasspath - maxParallelForks = Runtime.getRuntime().availableProcessors() / 2 + + // Configuration parameters to execute top-level classes in parallel but methods in same thread + systemProperties["junit.jupiter.execution.parallel.enabled"] = "true" + systemProperties["junit.jupiter.execution.parallel.mode.default"] = "same_thread" + systemProperties["junit.jupiter.execution.parallel.mode.classes.default"] = "concurrent" testLogging { events = ["passed", "skipped", "failed"] diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/CleanCommandTest.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/CleanCommandTest.java index 29fb1da6e62..a2ef93611fb 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/CleanCommandTest.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/CleanCommandTest.java @@ -11,13 +11,13 @@ import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Isolated; import software.amazon.smithy.utils.IoUtils; import software.amazon.smithy.utils.ListUtils; - +@Isolated public class CleanCommandTest { private static final String PROJECT_NAME = "simple-config-sources"; @Test diff --git a/smithy-cli/src/it/java/software/amazon/smithy/cli/InitCommandTest.java b/smithy-cli/src/it/java/software/amazon/smithy/cli/InitCommandTest.java index 102a97993af..ae8aef6364a 100644 --- a/smithy-cli/src/it/java/software/amazon/smithy/cli/InitCommandTest.java +++ b/smithy-cli/src/it/java/software/amazon/smithy/cli/InitCommandTest.java @@ -10,6 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Isolated; import software.amazon.smithy.utils.IoUtils; import software.amazon.smithy.utils.ListUtils; @@ -20,6 +21,7 @@ import java.util.Collections; import java.util.List; +@Isolated public class InitCommandTest { private static final String PROJECT_NAME = "smithy-templates";