Skip to content

Commit

Permalink
feat(tests): run in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
jenspots committed Sep 15, 2024
1 parent ace9ec9 commit 79df52b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 33 deletions.
7 changes: 6 additions & 1 deletion orchestrator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
70 changes: 45 additions & 25 deletions orchestrator/src/test/kotlin/e2e/E2ETest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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." }
Expand All @@ -41,27 +46,42 @@ class E2ETest {

assert(valid.readText().contains("<Ghent>"))
assert(report.readText().contains("sh:Violation"))

if (web != null) {
assert(web.exists()) { "The web page should exist." }
assert(web.readText().contains("<title>Example Domain</title>"))
}
}

@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("<title>Example Domain</title>"))
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)
}
}
6 changes: 3 additions & 3 deletions orchestrator/src/test/resources/e2e/jvm.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ test:SHACLValidator
test:HttpWriter
a rdfc:FileWriterKT ;
rdfc:arguments [
rdfc:path </tmp/rdfc-testing/web.html> ;
rdfc:path </tmp/rdfc-testing-jvm-web.html> ;
rdfc:incoming test:web ;
] .

test:FileWriter
a rdfc:FileWriterKT ;
rdfc:arguments [
rdfc:path </tmp/rdfc-testing/valid.ttl> ;
rdfc:path </tmp/rdfc-testing-jvm-valid.ttl> ;
rdfc:incoming test:validated ;
] .

test:ReportWriter
a rdfc:FileWriterKT ;
rdfc:arguments [
rdfc:path </tmp/rdfc-testing/report.ttl> ;
rdfc:path </tmp/rdfc-testing-jvm-report.ttl> ;
rdfc:incoming test:report ;
] .
4 changes: 2 additions & 2 deletions orchestrator/src/test/resources/e2e/node.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ test:SHACLValidator
test:FileWriter
a rdfc:FileWriterTS ;
rdfc:arguments [
rdfc:path </tmp/rdfc-testing/valid.ttl> ;
rdfc:path </tmp/rdfc-testing-node-valid.ttl> ;
rdfc:incoming test:validated ;
] .

test:ReportWriter
a rdfc:FileWriterTS ;
rdfc:arguments [
rdfc:path </tmp/rdfc-testing/report.ttl> ;
rdfc:path </tmp/rdfc-testing-node-report.ttl> ;
rdfc:incoming test:report ;
] .
4 changes: 2 additions & 2 deletions orchestrator/src/test/resources/e2e/python.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ test:PythonProcessor
test:FileWriter
a rdfc:FileWriterKT ;
rdfc:arguments [
rdfc:path </tmp/rdfc-testing/valid.ttl> ;
rdfc:path </tmp/rdfc-testing-python-valid.ttl> ;
rdfc:incoming test:validated ;
] .

test:ReportWriter
a rdfc:FileWriterKT ;
rdfc:arguments [
rdfc:path </tmp/rdfc-testing/report.ttl> ;
rdfc:path </tmp/rdfc-testing-python-report.ttl> ;
rdfc:incoming test:report ;
] .
2 changes: 2 additions & 0 deletions orchestrator/src/test/resources/junit-platform.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent

0 comments on commit 79df52b

Please sign in to comment.