From 79df52b60f9cbc780306c21b18e24bf7d066a6df Mon Sep 17 00:00:00 2001 From: Jens Pots Date: Sun, 15 Sep 2024 14:55:10 +0200 Subject: [PATCH] feat(tests): run in parallel --- orchestrator/build.gradle.kts | 7 +- orchestrator/src/test/kotlin/e2e/E2ETest.kt | 70 ++++++++++++------- orchestrator/src/test/resources/e2e/jvm.ttl | 6 +- orchestrator/src/test/resources/e2e/node.ttl | 4 +- .../src/test/resources/e2e/python.ttl | 4 +- .../test/resources/junit-platform.properties | 2 + 6 files changed, 60 insertions(+), 33 deletions(-) create mode 100644 orchestrator/src/test/resources/junit-platform.properties diff --git a/orchestrator/build.gradle.kts b/orchestrator/build.gradle.kts index d670f8a..6f89018 100644 --- a/orchestrator/build.gradle.kts +++ b/orchestrator/build.gradle.kts @@ -34,7 +34,12 @@ tasks.shadowJar { tasks.test { useJUnitPlatform() - testLogging { showStandardStreams = true } + /** Set concurrency. */ + maxParallelForks = Runtime.getRuntime().availableProcessors() + setForkEvery(1) + forkEvery = 100L + + testLogging { events("passed", "skipped", "failed") } } /** We define these explicitly due to the reliance on Protobuf and gRPC. */ diff --git a/orchestrator/src/test/kotlin/e2e/E2ETest.kt b/orchestrator/src/test/kotlin/e2e/E2ETest.kt index 746a2b7..e9911cc 100644 --- a/orchestrator/src/test/kotlin/e2e/E2ETest.kt +++ b/orchestrator/src/test/kotlin/e2e/E2ETest.kt @@ -3,34 +3,39 @@ package e2e import java.io.File import kotlin.test.Test import kotlin.test.assertNotNull -import kotlinx.coroutines.TimeoutCancellationException import kotlinx.coroutines.runBlocking -import kotlinx.coroutines.withTimeout -import org.jetbrains.kotlin.incremental.createDirectory import technology.idlab.exec class E2ETest { - private fun run(resource: String) { - // Create the output directory. - val directory = File("/tmp/rdfc-testing") - directory.createDirectory() + data class Config( + val ttl: String, + val valid: String, + val report: String, + val web: String? = null + ) + private fun run(config: Config) = runBlocking { // Reset output files. - val valid = File("/tmp/rdfc-testing/valid.ttl") + val valid = File(config.valid) valid.delete() - val report = File("/tmp/rdfc-testing/report.ttl") + + val report = File(config.report) report.delete() + val web = + if (config.web != null) { + File(config.web) + } else { + null + } + web?.delete() + // Read the pipeline file. - val pipeline = this::class.java.getResource(resource) + val pipeline = this::class.java.getResource(config.ttl) assertNotNull(pipeline, "The file should exist.") // Execute the pipeline. - runBlocking { - try { - withTimeout(30_000) { exec(pipeline.path) } - } catch (_: TimeoutCancellationException) {} - } + exec(pipeline.path) // Check the output files. assert(valid.exists()) { "The valid file should exist." } @@ -41,27 +46,42 @@ class E2ETest { assert(valid.readText().contains("")) assert(report.readText().contains("sh:Violation")) + + if (web != null) { + assert(web.exists()) { "The web page should exist." } + assert(web.readText().contains("Example Domain")) + } } @Test fun python() { - run("/e2e/python.ttl") + val config = + Config( + "/e2e/python.ttl", + "/tmp/rdfc-testing-python-valid.ttl", + "/tmp/rdfc-testing-python-report.ttl") + run(config) } @Test fun node() { - run("/e2e/node.ttl") + val config = + Config( + "/e2e/node.ttl", + "/tmp/rdfc-testing-node-valid.ttl", + "/tmp/rdfc-testing-node-report.ttl") + run(config) } @Test fun jvm() { - // Remove the web page if it already exists. - val webPage = File("/tmp/rdfc-testing/web.html") - webPage.delete() - - run("/e2e/jvm.ttl") - - // Check if web page has been fetched and written to disk. - assert(webPage.readText().contains("Example Domain")) + val config = + Config( + "/e2e/jvm.ttl", + "/tmp/rdfc-testing-jvm-valid.ttl", + "/tmp/rdfc-testing-jvm-report.ttl", + "/tmp/rdfc-testing-jvm-web.html", + ) + run(config) } } diff --git a/orchestrator/src/test/resources/e2e/jvm.ttl b/orchestrator/src/test/resources/e2e/jvm.ttl index 592d035..ff1e364 100644 --- a/orchestrator/src/test/resources/e2e/jvm.ttl +++ b/orchestrator/src/test/resources/e2e/jvm.ttl @@ -58,20 +58,20 @@ test:SHACLValidator test:HttpWriter a rdfc:FileWriterKT ; rdfc:arguments [ - rdfc:path ; + rdfc:path ; rdfc:incoming test:web ; ] . test:FileWriter a rdfc:FileWriterKT ; rdfc:arguments [ - rdfc:path ; + rdfc:path ; rdfc:incoming test:validated ; ] . test:ReportWriter a rdfc:FileWriterKT ; rdfc:arguments [ - rdfc:path ; + rdfc:path ; rdfc:incoming test:report ; ] . diff --git a/orchestrator/src/test/resources/e2e/node.ttl b/orchestrator/src/test/resources/e2e/node.ttl index f7faf95..5759ae4 100644 --- a/orchestrator/src/test/resources/e2e/node.ttl +++ b/orchestrator/src/test/resources/e2e/node.ttl @@ -47,13 +47,13 @@ test:SHACLValidator test:FileWriter a rdfc:FileWriterTS ; rdfc:arguments [ - rdfc:path ; + rdfc:path ; rdfc:incoming test:validated ; ] . test:ReportWriter a rdfc:FileWriterTS ; rdfc:arguments [ - rdfc:path ; + rdfc:path ; rdfc:incoming test:report ; ] . diff --git a/orchestrator/src/test/resources/e2e/python.ttl b/orchestrator/src/test/resources/e2e/python.ttl index cf8a54a..9614576 100644 --- a/orchestrator/src/test/resources/e2e/python.ttl +++ b/orchestrator/src/test/resources/e2e/python.ttl @@ -45,13 +45,13 @@ test:PythonProcessor test:FileWriter a rdfc:FileWriterKT ; rdfc:arguments [ - rdfc:path ; + rdfc:path ; rdfc:incoming test:validated ; ] . test:ReportWriter a rdfc:FileWriterKT ; rdfc:arguments [ - rdfc:path ; + rdfc:path ; rdfc:incoming test:report ; ] . diff --git a/orchestrator/src/test/resources/junit-platform.properties b/orchestrator/src/test/resources/junit-platform.properties new file mode 100644 index 0000000..317c292 --- /dev/null +++ b/orchestrator/src/test/resources/junit-platform.properties @@ -0,0 +1,2 @@ +junit.jupiter.execution.parallel.enabled = true +junit.jupiter.execution.parallel.mode.default = concurrent