mumrah commented on code in PR #18770: URL: https://github.com/apache/kafka/pull/18770#discussion_r1966038212
########## test-common/test-common-util/src/main/java/org/apache/kafka/common/test/junit/QuarantinedPostDiscoveryFilter.java: ########## @@ -39,49 +41,101 @@ 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 RUN_NEW_PROP = "kafka.test.run.new"; + + public static final String RUN_FLAKY_PROP = "kafka.test.run.flaky"; public static final String CATALOG_FILE_PROP = "kafka.test.catalog.file"; + public static final String VERBOSE_PROP = "kafka.test.verbose"; + + private static final Logger log = LoggerFactory.getLogger(QuarantinedPostDiscoveryFilter.class); + private final Filter<TestDescriptor> autoQuarantinedFilter; - private final boolean runQuarantined; + + private final boolean runNew; + + private final boolean runFlaky; + + private final boolean verbose; // No-arg public constructor for SPI @SuppressWarnings("unused") public QuarantinedPostDiscoveryFilter() { - runQuarantined = System.getProperty(RUN_QUARANTINED_PROP, "false") + runNew = System.getProperty(RUN_NEW_PROP, "false") + .equalsIgnoreCase("true"); + + runFlaky = System.getProperty(RUN_FLAKY_PROP, "false") + .equalsIgnoreCase("true"); + + verbose = System.getProperty(VERBOSE_PROP, "false") .equalsIgnoreCase("true"); String testCatalogFileName = System.getProperty(CATALOG_FILE_PROP); - autoQuarantinedFilter = AutoQuarantinedTestFilter.create(testCatalogFileName, runQuarantined); + autoQuarantinedFilter = AutoQuarantinedTestFilter.create(testCatalogFileName); } // Visible for tests - QuarantinedPostDiscoveryFilter(Filter<TestDescriptor> autoQuarantinedFilter, boolean runQuarantined) { + QuarantinedPostDiscoveryFilter( + Filter<TestDescriptor> autoQuarantinedFilter, + boolean runNew, + boolean runFlaky + ) { this.autoQuarantinedFilter = autoQuarantinedFilter; - this.runQuarantined = runQuarantined; + this.runNew = runNew; + this.runFlaky = runFlaky; + this.verbose = false; } @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 first check for explicitly flaky tests. If no - // flaky tag is set, check the auto-quarantined filter. In the case of a missing test - // catalog, the auto-quarantined filter will exclude all tests. - if (hasTag) { - return FilterResult.included("flaky"); + boolean hasFlakyTag = testDescriptor.getTags().contains(FLAKY_TEST_TAG); + FilterResult autoQuarantinedResult = autoQuarantinedFilter.apply(testDescriptor); + + final FilterResult result; + if (runFlaky && runNew) { + // If selecting flaky and quarantined tests, we first check for explicitly flaky tests. + // If no flaky tag is set, defer to the auto-quarantined filter. + if (hasFlakyTag) { + result = FilterResult.included("flaky"); + } else { + result = autoQuarantinedResult; + } + } else if (runFlaky) { + // If selecting only flaky, just check the tag. Don't use the auto-quarantined filter + if (hasFlakyTag) { + result = FilterResult.included("flaky"); } else { - return result; + result = FilterResult.excluded("non-flaky"); + } + } else if (runNew) { + // Running only auto-quarantined + if (autoQuarantinedResult.included() && hasFlakyTag) { + result = FilterResult.excluded("flaky"); + } else { + result = autoQuarantinedResult; } } else { - // If selecting non-quarantined tests, we exclude auto-quarantined tests and flaky tests - if (result.included() && hasTag) { - return FilterResult.excluded("flaky"); + // The main test suite + if (hasFlakyTag) { + result = FilterResult.excluded("flaky"); + } else if (autoQuarantinedResult.included()) { + result = FilterResult.excluded("new"); } else { - return result; + result = FilterResult.included(null); } } + + if (verbose) { + log.info( Review Comment: I believe this uses Gradle's logger rather than Kafka's. I could be wrong though. When I run ``` ./gradlew --scan --info -Pkafka.test.run.flaky=true :metadata:cleanTest :metadata:test ``` I get the expected output on the command line ``` Gradle Test Executor 3 STANDARD_OUT [2025-02-21 14:07:37,972] INFO Including Test 'JUnit Jupiter' with reason 'null'. Flaky tag is not present, auto-quarantined filter has not included this test. (org.apache.kafka.common.test.junit.QuarantinedPostDiscoveryFilter:130) ``` -- 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