Apache Lucene open-source search software
LUCENE-13829: don't enforce the sysout limit when tests.iters >1 (#16535)
Jakub Slowinski010f0da788c6
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/util/TestRuleLimitSysouts.java b/lucene/test-framework/src/java/org/apache/lucene/tests/util/TestRuleLimitSysouts.javaindex 20f68cf26bc..7b47b8540c1 100644--- a/lucene/test-framework/src/java/org/apache/lucene/tests/util/TestRuleLimitSysouts.java+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/util/TestRuleLimitSysouts.java@@ -17,6 +17,7 @@package org.apache.lucene.tests.util;import com.carrotsearch.randomizedtesting.RandomizedTest;+import com.carrotsearch.randomizedtesting.SysGlobals;import com.carrotsearch.randomizedtesting.rules.TestRuleAdapter;import java.io.IOException;import java.io.OutputStream;@@ -248,6 +249,7 @@ public class TestRuleLimitSysouts extends TestRuleAdapter {if (LuceneTestCase.VERBOSE|| LuceneTestCase.INFOSTREAM+ || isRepeatingTestCases()|| target.isAnnotationPresent(Monster.class)|| target.isAnnotationPresent(SuppressSysoutChecks.class)) {return false;@@ -260,6 +262,11 @@ public class TestRuleLimitSysouts extends TestRuleAdapter {return true;}+ /** Whether the runner repeats test cases, via {@code tests.iters}. */+ private static boolean isRepeatingTestCases() {+ return RandomizedTest.systemPropertyAsInt(SysGlobals.SYSPROP_ITERATIONS(), 1) > 1;+ }+/*** We're only interested in failing the suite if it was successful (otherwise just propagate the* original problem and don't bother doing anything else).diff --git a/lucene/test-framework/src/test/org/apache/lucene/tests/util/TestSysoutsLimits.java b/lucene/test-framework/src/test/org/apache/lucene/tests/util/TestSysoutsLimits.javaindex 3d2ef8b0d4d..c072096e808 100644--- a/lucene/test-framework/src/test/org/apache/lucene/tests/util/TestSysoutsLimits.java+++ b/lucene/test-framework/src/test/org/apache/lucene/tests/util/TestSysoutsLimits.java@@ -17,6 +17,7 @@package org.apache.lucene.tests.util;import com.carrotsearch.randomizedtesting.RandomizedTest;+import com.carrotsearch.randomizedtesting.SysGlobals;import java.util.stream.Collectors;import org.junit.Assert;import org.junit.Assume;@@ -78,6 +79,21 @@ public class TestSysoutsLimits extends WithNestedTests {Assert.assertTrue(msg, msg.contains("The test or suite printed 10 bytes"));}+ @Test+ public void testNotEnforcedWhenRepeatingTestCases() {+ String iters = SysGlobals.SYSPROP_ITERATIONS();+ try {+ // Still apply limit for single iter.+ System.setProperty(iters, "1");+ Assert.assertEquals(1, new JUnitCore().run(OverSoftLimit.class).getFailureCount());++ System.setProperty(iters, "3");+ Assert.assertEquals(0, new JUnitCore().run(OverSoftLimit.class).getFailureCount());+ } finally {+ System.clearProperty(iters);+ }+ }+@TestRuleLimitSysouts.Limit(bytes = 10)public static class UnderLimit extends ParentNestedTest {@Test