diff --git a/src/test/java/us/ihmc/ci/CategoriesTest.java b/src/test/java/us/ihmc/ci/CategoriesTest.java new file mode 100644 index 00000000..f0099f5b --- /dev/null +++ b/src/test/java/us/ihmc/ci/CategoriesTest.java @@ -0,0 +1,52 @@ +package us.ihmc.ci; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import us.ihmc.build.GradleTestingToolsKt; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +@Tag("categories-test") +public class CategoriesTest +{ + @Test + public void testAllTestsRun() throws IOException + { + String projectName = "categories"; + GradleTestingToolsKt.runGradleTask("-v", projectName); + String cleanOutput = GradleTestingToolsKt.runGradleTask("clean", projectName); + Assertions.assertTrue(cleanOutput.contains("BUILD SUCCESSFUL")); + String output = GradleTestingToolsKt.runGradleTask("test --info -Pcategory=all", projectName); + Assertions.assertTrue(output.contains("BUILD FAILED")); + + System.out.println("Working dir: " + Paths.get(".").toAbsolutePath()); + String results = Files.readString(Paths.get("tests/categories/src/test/build/reports/tests/test/index.html")); + System.out.println(results); + // Asserts 11 tests pass, 1 test fails, 0 tests ignored + Assertions.assertTrue(results.contains( + "us.ihmc.ci" + System.lineSeparator() + "" + System.lineSeparator() + "9" + + System.lineSeparator() + "1" + System.lineSeparator() + "0")); + } + + @Test + public void testFastTestsRun() throws IOException + { + String projectName = "categories"; + GradleTestingToolsKt.runGradleTask("-v", projectName); + String cleanOutput = GradleTestingToolsKt.runGradleTask("clean", projectName); + Assertions.assertTrue(cleanOutput.contains("BUILD SUCCESSFUL")); + String output = GradleTestingToolsKt.runGradleTask("test --info -PincludeTags=fast", projectName); + Assertions.assertTrue(output.contains("BUILD SUCCESSFUL")); + + System.out.println("Working dir: " + Paths.get(".").toAbsolutePath()); + String results = Files.readString(Paths.get("tests/categories/src/test/build/reports/tests/test/index.html")); + System.out.println(results); + // Asserts 5 tests pass, 0 test fails, 0 tests ignored + Assertions.assertTrue(results.contains( + "us.ihmc.ci" + System.lineSeparator() + "" + System.lineSeparator() + "4" + + System.lineSeparator() + "0" + System.lineSeparator() + "0")); + } +} diff --git a/src/test/java/us/ihmc/ci/CategorizedExtendingExtreme.java b/src/test/java/us/ihmc/ci/CategorizedExtendingExtreme.java new file mode 100644 index 00000000..b8029453 --- /dev/null +++ b/src/test/java/us/ihmc/ci/CategorizedExtendingExtreme.java @@ -0,0 +1,5 @@ +package us.ihmc.ci; + +public class CategorizedExtendingExtreme // extends CategorizedAbstractTest +{ +} diff --git a/src/test/java/us/ihmc/ci/CategorizedExtendingTest.java b/src/test/java/us/ihmc/ci/CategorizedExtendingTest.java new file mode 100644 index 00000000..594d164d --- /dev/null +++ b/src/test/java/us/ihmc/ci/CategorizedExtendingTest.java @@ -0,0 +1,12 @@ +package us.ihmc.ci; + +import org.junit.jupiter.api.Test; + +public class CategorizedExtendingTest //extends CategorizedAbstractTest +{ + @Test + public void imAndExtendingTest() + { + //super.imAnAbstractTest(); + } +} diff --git a/src/test/java/us/ihmc/ci/CategorizedTests1.java b/src/test/java/us/ihmc/ci/CategorizedTests1.java new file mode 100644 index 00000000..5de59739 --- /dev/null +++ b/src/test/java/us/ihmc/ci/CategorizedTests1.java @@ -0,0 +1,48 @@ +package us.ihmc.ci; + +import org.junit.jupiter.api.Assertions; +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; +import org.junit.jupiter.api.parallel.ExecutionMode; +import org.junit.jupiter.api.parallel.ResourceAccessMode; +import org.junit.jupiter.api.parallel.ResourceLock; + +public class CategorizedTests1 +{ + @Tag("fast") + @Test + public void fastTest() throws InterruptedException + { + } + + @Test + public void untaggedTest() + { + + } + + @Disabled + @Tag("failing") + @Test + public void failingTest() throws InterruptedException + { + Assertions.fail(); + } + + @ResourceLock(value = "File.txt", mode = ResourceAccessMode.READ_WRITE) + @Execution(ExecutionMode.SAME_THREAD) + @Tag("slow") + @Test + public void slowTest() throws InterruptedException + { + } + + @Tag("fast") + @Tag("needs-gpu") + @Test + public void gpuTest() throws InterruptedException + { + } +} diff --git a/src/test/java/us/ihmc/ci/CategorizedTests2.java b/src/test/java/us/ihmc/ci/CategorizedTests2.java new file mode 100644 index 00000000..5873f0ac --- /dev/null +++ b/src/test/java/us/ihmc/ci/CategorizedTests2.java @@ -0,0 +1,31 @@ +package us.ihmc.ci; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +public class CategorizedTests2 +{ + @Tag("fast") + @Test + public void fastTest() throws InterruptedException + { + } + + @Test + public void untaggedTest() throws InterruptedException + { + } + + @Tag("slow") + @Test + public void slowTest() throws InterruptedException + { + } + + @Tag("fast") + @Tag("needs-gpu") + @Test + public void gpuTest() throws InterruptedException + { + } +} diff --git a/src/test/java/us/ihmc/ci/ParallelExecutionTest.java b/src/test/java/us/ihmc/ci/ParallelExecutionTest.java new file mode 100644 index 00000000..bf393f01 --- /dev/null +++ b/src/test/java/us/ihmc/ci/ParallelExecutionTest.java @@ -0,0 +1,50 @@ +package us.ihmc.ci; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import us.ihmc.build.GradleTestingToolsKt; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class ParallelExecutionTest +{ + @Test + public void testAllTestsRun() throws IOException + { + String projectName = "categories"; + GradleTestingToolsKt.runGradleTask("-v", projectName); + String cleanOutput = GradleTestingToolsKt.runGradleTask("clean", projectName); + Assertions.assertTrue(cleanOutput.contains("BUILD SUCCESSFUL")); + String output = GradleTestingToolsKt.runGradleTask("test --info -Pcategory=all", projectName); + Assertions.assertTrue(output.contains("BUILD FAILED")); + + System.out.println("Working dir: " + Paths.get(".").toAbsolutePath()); + String results = new String(Files.readAllBytes(Paths.get("tests/categories/src/test/build/reports/tests/test/index.html"))); + System.out.println(results); + // Asserts 11 tests pass, 1 test fails, 0 tests ignored + Assertions.assertTrue(results.contains( + "us.ihmc.ci" + System.lineSeparator() + "" + System.lineSeparator() + "9" + + System.lineSeparator() + "1" + System.lineSeparator() + "0")); + } + + @Test + public void testFastTestsRun() throws IOException + { + String projectName = "categories"; + GradleTestingToolsKt.runGradleTask("-v", projectName); + String cleanOutput = GradleTestingToolsKt.runGradleTask("clean", projectName); + Assertions.assertTrue(cleanOutput.contains("BUILD SUCCESSFUL")); + String output = GradleTestingToolsKt.runGradleTask("test --info -Pcategory=fast", projectName); + Assertions.assertTrue(output.contains("BUILD SUCCESSFUL")); + + System.out.println("Working dir: " + Paths.get(".").toAbsolutePath()); + String results = new String(Files.readAllBytes(Paths.get("tests/categories/src/test/build/reports/tests/test/index.html"))); + System.out.println(results); + // Asserts 5 tests pass, 0 test fails, 0 tests ignored + Assertions.assertTrue(results.contains( + "us.ihmc.ci" + System.lineSeparator() + "" + System.lineSeparator() + "4" + + System.lineSeparator() + "0" + System.lineSeparator() + "0")); + } +} diff --git a/tests/categories/build.gradle.kts b/tests/categories/build.gradle.kts new file mode 100644 index 00000000..1d463a83 --- /dev/null +++ b/tests/categories/build.gradle.kts @@ -0,0 +1,31 @@ +plugins { + id("us.ihmc.ihmc-build") + id("us.ihmc.log-tools-plugin") version "0.6.3" + id("us.ihmc.ihmc-ci") version "7.7" + id("us.ihmc.ihmc-cd") version "1.23" +} + +ihmc { + group = "us.ihmc" + version = "0.1.0" + vcsUrl = "https://your.vcs/url" + openSource = true + + configureDependencyResolution() + configurePublications() +} + +//categories.configure("all") { +// +//} + +//ihmc.sourceSetProject("test").tasks.named("test", Test::class.java) { +// +//} + +mainDependencies { + api("org.apache.commons:commons-lang3:3.12.0") +} + +testDependencies { +} diff --git a/tests/categories/gradle.properties b/tests/categories/gradle.properties new file mode 100644 index 00000000..1d6102c0 --- /dev/null +++ b/tests/categories/gradle.properties @@ -0,0 +1,20 @@ +kebabCasedName = categories +pascalCasedName = Categories +extraSourceSets = ["test"] +publishUrl = local +compositeSearchHeight = 0 +excludeFromCompositeBuild = false +artifactoryUsername = unset_username +artifactoryPassword = unset_password + +# Test suite generator +disableJobCheck = true +crashOnEmptyJobs = false +crashOnMissingTimeouts = true +disableSuiteBalancing = false +maxSuiteDuration = 5.5 +bambooUrl = "https://bamboo.ihmc.us/" +bambooPlanKeys = ["one", "two"] + +includeTags = all +excludeTags = none \ No newline at end of file diff --git a/tests/categories/settings.gradle.kts b/tests/categories/settings.gradle.kts new file mode 100644 index 00000000..58165093 --- /dev/null +++ b/tests/categories/settings.gradle.kts @@ -0,0 +1,20 @@ +pluginManagement { + plugins { + id("us.ihmc.ihmc-build") version "0.29.3" + } +} + +buildscript { + repositories { + maven { url = uri("https://plugins.gradle.org/m2/") } + mavenLocal() + } + dependencies { + classpath("us.ihmc:ihmc-build:0.29.3") + } +} + +val ihmcSettingsConfigurator = us.ihmc.build.IHMCSettingsConfigurator(settings, logger, extra) +ihmcSettingsConfigurator.checkRequiredPropertiesAreSet() +ihmcSettingsConfigurator.configureExtraSourceSets() +ihmcSettingsConfigurator.findAndIncludeCompositeBuilds() diff --git a/tests/categories/src/main/java/us.ihmc/BasicTestApplication.java b/tests/categories/src/main/java/us.ihmc/BasicTestApplication.java new file mode 100644 index 00000000..286bcdcb --- /dev/null +++ b/tests/categories/src/main/java/us.ihmc/BasicTestApplication.java @@ -0,0 +1,9 @@ +package us.ihmc; + +public class BasicTestApplication +{ + public static void main(String[] args) + { + System.out.println("Hello there. I'm some test code."); + } +} diff --git a/tests/categories/src/test/java/us/ihmc/ci/CategorizedAbstractTest.java b/tests/categories/src/test/java/us/ihmc/ci/CategorizedAbstractTest.java new file mode 100644 index 00000000..587cf306 --- /dev/null +++ b/tests/categories/src/test/java/us/ihmc/ci/CategorizedAbstractTest.java @@ -0,0 +1,24 @@ +package us.ihmc.ci; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import java.time.Duration; + +public abstract class CategorizedAbstractTest +{ + public void imAnAbstractTest() + { + + } + + @Tag("fast") + @Test + public void someNonExtendedTest() + { + Assertions.assertTimeout(Duration.ofSeconds(30), () -> { + + }); + } +} diff --git a/tests/categories/src/test/java/us/ihmc/ci/CategorizedTests3.java b/tests/categories/src/test/java/us/ihmc/ci/CategorizedTests3.java new file mode 100644 index 00000000..4afa1c76 --- /dev/null +++ b/tests/categories/src/test/java/us/ihmc/ci/CategorizedTests3.java @@ -0,0 +1,46 @@ +package us.ihmc.ci; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; +import org.junit.jupiter.api.parallel.ResourceAccessMode; +import org.junit.jupiter.api.parallel.ResourceLock; + +public class CategorizedTests3 +{ + @Tag("fast") + @Test + public void fastTest() throws InterruptedException + { + } + + @Test + public void untaggedTest() + { + + } + + @Tag("failing") + @Test + public void failingTest() throws InterruptedException + { + Assertions.fail(); + } + + @ResourceLock(value = "File.txt", mode = ResourceAccessMode.READ_WRITE) + @Execution(ExecutionMode.SAME_THREAD) + @Tag("slow") + @Test + public void slowTest() throws InterruptedException + { + } + + @Tag("fast") + @Tag("needs-gpu") + @Test + public void gpuTest() throws InterruptedException + { + } +} diff --git a/tests/categories/src/test/java/us/ihmc/ci/CategorizedTests4.java b/tests/categories/src/test/java/us/ihmc/ci/CategorizedTests4.java new file mode 100644 index 00000000..244e017d --- /dev/null +++ b/tests/categories/src/test/java/us/ihmc/ci/CategorizedTests4.java @@ -0,0 +1,31 @@ +package us.ihmc.ci; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +public class CategorizedTests4 +{ + @Tag("fast") + @Test + public void fastTest() throws InterruptedException + { + } + + @Test + public void untaggedTest() throws InterruptedException + { + } + + @Tag("slow") + @Test + public void slowTest() throws InterruptedException + { + } + + @Tag("fast") + @Tag("needs-gpu") + @Test + public void gpuTest() throws InterruptedException + { + } +} diff --git a/tests/parallel-execution/build.gradle.kts b/tests/parallel-execution/build.gradle.kts new file mode 100644 index 00000000..fb2fc6ee --- /dev/null +++ b/tests/parallel-execution/build.gradle.kts @@ -0,0 +1,32 @@ +plugins { + id("us.ihmc.ihmc-build") + id("us.ihmc.log-tools-plugin") version "0.6.3" + id("us.ihmc.ihmc-ci") version "7.7" + id("us.ihmc.ihmc-cd") version "1.23" +} + +ihmc { + group = "us.ihmc" + version = "0.1.0" + vcsUrl = "https://your.vcs/url" + openSource = true + + configureDependencyResolution() + configurePublications() +} + +ihmc.sourceSetProject("test").tasks.named("test", Test::class.java) { + setForkEvery(1) + maxParallelForks = 20 + + systemProperties["junit.jupiter.execution.parallel.enabled"] = "true" + systemProperties["junit.jupiter.execution.parallel.config.strategy"] = "dynamic" +// systemProperties["junit.jupiter.execution.parallel.config.fixed.parallelism"] = "2" +} + +mainDependencies { + api("org.apache.commons:commons-lang3:3.12.0") +} + +testDependencies { +} diff --git a/tests/parallel-execution/gradle.properties b/tests/parallel-execution/gradle.properties new file mode 100644 index 00000000..1864a592 --- /dev/null +++ b/tests/parallel-execution/gradle.properties @@ -0,0 +1,9 @@ +kebabCasedName = parallel-execution +pascalCasedName = ParallelExecution +extraSourceSets = ["test"] +publishUrl = local +compositeSearchHeight = 0 +excludeFromCompositeBuild = false + +includeTags = all +excludeTags = none \ No newline at end of file diff --git a/tests/parallel-execution/settings.gradle.kts b/tests/parallel-execution/settings.gradle.kts new file mode 100644 index 00000000..58165093 --- /dev/null +++ b/tests/parallel-execution/settings.gradle.kts @@ -0,0 +1,20 @@ +pluginManagement { + plugins { + id("us.ihmc.ihmc-build") version "0.29.3" + } +} + +buildscript { + repositories { + maven { url = uri("https://plugins.gradle.org/m2/") } + mavenLocal() + } + dependencies { + classpath("us.ihmc:ihmc-build:0.29.3") + } +} + +val ihmcSettingsConfigurator = us.ihmc.build.IHMCSettingsConfigurator(settings, logger, extra) +ihmcSettingsConfigurator.checkRequiredPropertiesAreSet() +ihmcSettingsConfigurator.configureExtraSourceSets() +ihmcSettingsConfigurator.findAndIncludeCompositeBuilds() diff --git a/tests/parallel-execution/src/main/java/us.ihmc/BasicTestApplication.java b/tests/parallel-execution/src/main/java/us.ihmc/BasicTestApplication.java new file mode 100644 index 00000000..286bcdcb --- /dev/null +++ b/tests/parallel-execution/src/main/java/us.ihmc/BasicTestApplication.java @@ -0,0 +1,9 @@ +package us.ihmc; + +public class BasicTestApplication +{ + public static void main(String[] args) + { + System.out.println("Hello there. I'm some test code."); + } +} diff --git a/tests/parallel-execution/src/test/java/us/ihmc/ParallelExecution1.java b/tests/parallel-execution/src/test/java/us/ihmc/ParallelExecution1.java new file mode 100644 index 00000000..824358fc --- /dev/null +++ b/tests/parallel-execution/src/test/java/us/ihmc/ParallelExecution1.java @@ -0,0 +1,44 @@ +package us.ihmc; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; +import org.junit.jupiter.api.parallel.ResourceAccessMode; +import org.junit.jupiter.api.parallel.ResourceLock; + +import java.time.Duration; + +public class ParallelExecution1 +{ + @Tag("fast") + @Test + public void fastTest() throws InterruptedException + { + Thread.sleep(5000); + } + + @Test + public void untaggedTest() throws InterruptedException + { + Thread.sleep(5000); + } + + @ResourceLock(value = "File.txt", mode = ResourceAccessMode.READ_WRITE) + @Execution(ExecutionMode.SAME_THREAD) + @Tag("slow") + @Test + public void slowTest() throws InterruptedException + { + Thread.sleep(5000); + } + + @Tag("fast") + @Tag("needs-gpu") + @Test + public void gpuTest() throws InterruptedException + { + Thread.sleep(5000); + } +} diff --git a/tests/parallel-execution/src/test/java/us/ihmc/ParallelExecution2.java b/tests/parallel-execution/src/test/java/us/ihmc/ParallelExecution2.java new file mode 100644 index 00000000..8bdc9dd6 --- /dev/null +++ b/tests/parallel-execution/src/test/java/us/ihmc/ParallelExecution2.java @@ -0,0 +1,35 @@ +package us.ihmc; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +public class ParallelExecution2 +{ + @Tag("fast") + @Test + public void fastTest() throws InterruptedException + { + Thread.sleep(5000); + } + + @Test + public void untaggedTest() throws InterruptedException + { + Thread.sleep(5000); + } + + @Tag("slow") + @Test + public void slowTest() throws InterruptedException + { + Thread.sleep(5000); + } + + @Tag("fast") + @Tag("needs-gpu") + @Test + public void gpuTest() throws InterruptedException + { + Thread.sleep(5000); + } +}