nevzheng commented on code in PR #13517:
URL: https://github.com/apache/gravitino/pull/13517#discussion_r4147533203
##########
core/build.gradle.kts:
##########
@@ -103,7 +106,164 @@ artifacts {
add("testArtifacts", testJar)
}
+// Core's tests run in one of four Gradle lanes: coreUnitTest (default, no
Docker) and
+// coreH2Test/coreMySQLTest/corePostgreSQLTest (one per backend, coreMySQLTest
and
+// corePostgreSQLTest need Docker). Lane membership is decided purely by which
of the three
+// backend tags below a test class carries - see CoreBackend in
+// core/src/test/java/org/apache/gravitino/storage/relational/CoreBackend.java
for the typed
+// annotations (@CoreBackend.H2/.MySQL/.PostgreSQL/.All) that set them,
instead of writing raw
+// @Tag("...") strings by hand:
+// @CoreBackend.H2 -> runs only in coreH2Test
+// @CoreBackend.H2 @CoreBackend.MySQL -> runs in coreH2Test and
coreMySQLTest
+// @CoreBackend.All -> runs in all three backend lanes
+// (no CoreBackend annotation at all) -> a plain unit test, runs in
coreUnitTest
+// A class needing Docker but carrying no backend tag runs in no lane at all -
check locally
+// with `./gradlew :core:coreTestLaneOf
-PclassName=<fully.qualified.ClassName>`.
+//
+// Backend name -> JUnit tag that admits a test class to that backend's lane.
Adding a backend
+// here is enough to teach the lane filtering below about it; also add it to
CoreBackend.java.
+val coreBackendTestTags =
+ linkedMapOf(
+ "h2" to "gravitino-core-h2-test",
+ "mysql" to "gravitino-core-mysql-test",
+ "postgresql" to "gravitino-core-postgresql-test"
+ )
+val coreTestBackendProperty = "gravitino.core.test.backend"
+
+fun registerCoreTestTask(
+ taskName: String,
+ backend: String? = null
+) = tasks.register<Test>(taskName) {
+ group = "verification"
+ description =
+ if (backend == null) {
+ "Runs core unit tests."
+ } else {
+ "Runs core database tests against $backend."
+ }
+
+ testClassesDirs = sourceSets["test"].output.classesDirs
+ classpath = sourceSets["test"].runtimeClasspath
+
+ inputs.property("coreTestSuite", backend ?: "unit")
+ inputs.property("coreTestBackend", backend ?: "none")
+ // Distinct from the extensions.extraProperties["includeDockerTaggedTests"]
flag set below,
+ // which is a different mechanism (read by root build.gradle.kts's shared
test-environment
+ // setup to decide JUnit tag filtering) - this is only a Gradle
up-to-date-check input.
+ inputs.property("coreTestIncludesDockerTaggedTests", backend != null)
+
reports.junitXml.outputLocation.set(layout.buildDirectory.dir("test-results/$taskName"))
+ reports.html.outputLocation.set(
+ rootProject.layout.buildDirectory.dir("reports/tests/core/$taskName")
+ )
+
+ extensions.configure<JacocoTaskExtension> {
+ destinationFile =
layout.buildDirectory.file("jacoco/$taskName.exec").get().asFile
+ }
+
+ useJUnitPlatform {
+ if (backend == null) {
+ // Whatever carries no backend tag (and no Docker tag) is the unit suite.
+ excludeTags(*coreBackendTestTags.values.toTypedArray(),
"gravitino-docker-test")
+ } else {
+ val ownBackendTag =
+ coreBackendTestTags[backend]
+ ?: throw GradleException("Unsupported core test backend: $backend")
+ // Plain tag include, applied by JUnit at discovery time, so classes not
tagged for this
+ // backend never show up in this lane's JUnit XML. A class tagged for
several backends
+ // runs under each of them.
+ includeTags(ownBackendTag)
+ }
+ }
+
+ if (backend != null) {
+ systemProperty(coreTestBackendProperty, backend)
+ extensions.extraProperties["includeDockerTaggedTests"] = true
Review Comment:
**note (non-blocking):** There's no ordering dependency. The flag is read at
execution time, not configuration time.
`setTestEnvironment` wraps its whole body, including the
`includeDockerTaggedTests` read and `excludeTags("gravitino-docker-test")`, in
`param.doFirst { }` (root `build.gradle.kts:432-532`). That runs after every
`register`/`configureEach` action, and with the flag true nothing is excluded.
https://github.com/apache/gravitino/pull/13517/commits/67457136f87f1f7031d9615a5f2ebe0862d4b7f4
adds a comment at both ends saying the read must stay in `doFirst`.
<details><summary>Evidence</summary>
Ran locally (JDK 17): `./gradlew :core:coreH2Test --tests
TestEntityStorageForLance -PskipDockerTests=true` ran that Docker-tagged class:
2 tests, 0 failures.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]