chia7712 commented on code in PR #17725:
URL: https://github.com/apache/kafka/pull/17725#discussion_r1846107812


##########
build.gradle:
##########
@@ -1548,7 +1553,8 @@ project(':test-common') {
     implementation project(':storage')
     implementation project(':server-common')
     implementation libs.slf4jApi
-    testImplementation libs.junitJupiter
+    implementation libs.junitJupiter
+    implementation libs.junitPlatformLanucher

Review Comment:
   does `test-common` use them in production code?                          



##########
test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/junit/QuarantinedPostDiscoveryFilter.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.common.test.junit;
+
+import org.junit.platform.engine.Filter;
+import org.junit.platform.engine.FilterResult;
+import org.junit.platform.engine.TestDescriptor;
+import org.junit.platform.engine.TestTag;
+import org.junit.platform.launcher.PostDiscoveryFilter;
+
+/**
+ * A JUnit test filter which can include or exclude discovered tests before
+ * they are sent off to the test engine for execution. The behavior of this
+ * filter is controlled by the system property "kafka.test.run.quarantined".
+ * If the property is set to "true", then only auto-quarantined and explicitly
+ * "@Flaky" tests will be included. If the property is set to "false", then
+ * only non-quarantined tests will be run.
+ * <p>
+ * This filter is registered with JUnit using SPI. The test-common-runtime 
module
+ * includes a META-INF/services/org.junit.platform.launcher.PostDiscoveryFilter
+ * service file which registers this class.
+ */
+public class QuarantinedPostDiscoveryFilter implements PostDiscoveryFilter {
+
+    private static final TestTag FLAKY_TEST_TAG = TestTag.create("flaky");
+
+    public static final String RUN_QUARANTINED_PROP = 
"kafka.test.run.quarantined";
+
+    public static final String CATALOG_FILE_PROP = "kafka.test.catalog.file";
+
+    private final Filter<TestDescriptor> autoQuarantinedFilter;
+    private final boolean runQuarantined;
+
+    // No-arg constructor for SPI
+    public QuarantinedPostDiscoveryFilter() {
+        runQuarantined = System.getProperty(RUN_QUARANTINED_PROP, "false")
+            .equalsIgnoreCase("true");
+
+        String testCatalogFileName = System.getProperty(CATALOG_FILE_PROP);
+        autoQuarantinedFilter = 
AutoQuarantinedTestFilter.create(testCatalogFileName, runQuarantined);
+    }
+
+    // Visible for tests
+    QuarantinedPostDiscoveryFilter(Filter<TestDescriptor> 
autoQuarantinedFilter, boolean runQuarantined) {
+        this.autoQuarantinedFilter = autoQuarantinedFilter;
+        this.runQuarantined = runQuarantined;
+    }
+
+    @Override
+    public FilterResult apply(TestDescriptor testDescriptor) {
+        boolean hasTag = testDescriptor.getTags().contains(FLAKY_TEST_TAG);
+        FilterResult result = autoQuarantinedFilter.apply(testDescriptor);
+        if (runQuarantined) {
+            // If selecting quarantined tests, we include auto-quarantined 
tests and flaky tests
+            if (result.excluded() && hasTag) {

Review Comment:
   the command `./gradlew cleanTest metadata:quarantinedTest` will run all 
tests since `result.excluded()`  is always `true`. If we want to allow 
developers to run `quarantinedTest` locally, we should handle the case of 
nonexistent `kafka.test.catalog.file`.



##########
.github/scripts/junit.py:
##########
@@ -332,9 +334,20 @@ def split_report_path(base_path: str, report_path: str) -> 
Tuple[str, str]:
     report_md = f"Download [HTML report]({report_url})."
     summary = (f"{total_run} tests cases run in {duration}. "
                f"{total_success} {PASSED}, {total_failures} {FAILED}, "
-               f"{total_flaky} {FLAKY}, {total_skipped} {SKIPPED}, and 
{total_errors} errors.")
+               f"{total_flaky} {FLAKY}, {total_skipped} {SKIPPED}, 
{len(quarantined_table)} {QUARANTINED}, and {total_errors} errors.")
     print("## Test Summary\n")
     print(f"{summary} {report_md}\n")
+    if len(quarantined_table) > 0:
+        logger.info(f"Ran {len(quarantined_table)} quarantined test:")
+        print("<details>")
+        print(f"<summary>{len(quarantined_table)} Quarantined 
Tests</summary>\n")

Review Comment:
   There are four types of tests in the summary - `Quarantined`, `Flaky`, 
`Failed`, and `Skipped` - which makes it a bit chaotic. How about applying a 
consistent style to all of them to make the summary more readable?



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to