This is an automated email from the ASF dual-hosted git repository. fanrui pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/flink.git
commit a267e58e69babbdc6b2991ca480acc36b9556dcb Author: Rui Fan <[email protected]> AuthorDate: Sun Apr 12 22:18:22 2026 +0200 [FLINK-39423][tests] Fix PseudoRandomValueSelector.randomize() producing identical values for all boolean config options --- .../testutils/PseudoRandomValueSelector.java | 3 ++- .../testutils/PseudoRandomValueSelectorTest.java | 24 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/PseudoRandomValueSelector.java b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/PseudoRandomValueSelector.java index 7b545adce9c..4d890060f6a 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/PseudoRandomValueSelector.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/PseudoRandomValueSelector.java @@ -128,7 +128,8 @@ public class PseudoRandomValueSelector { public static <T> T randomize(Configuration conf, ConfigOption<T> option, T... t1) { final String testName = TestNameProvider.getCurrentTestName(); final PseudoRandomValueSelector valueSelector = - PseudoRandomValueSelector.create(testName != null ? testName : "unknown"); + PseudoRandomValueSelector.create( + (testName != null ? testName : "unknown") + option.key()); return valueSelector.select(conf, option, t1); } } diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/PseudoRandomValueSelectorTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/PseudoRandomValueSelectorTest.java index 138068046a3..57811db0924 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/PseudoRandomValueSelectorTest.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/testutils/PseudoRandomValueSelectorTest.java @@ -19,6 +19,7 @@ package org.apache.flink.runtime.testutils; import org.apache.flink.api.java.tuple.Tuple3; import org.apache.flink.configuration.ConfigOption; +import org.apache.flink.configuration.ConfigOptions; import org.apache.flink.configuration.Configuration; import org.apache.flink.configuration.MemorySize; import org.apache.flink.runtime.util.EnvironmentInformation; @@ -34,6 +35,7 @@ import java.util.stream.IntStream; import static org.apache.flink.configuration.CheckpointingOptions.SAVEPOINT_DIRECTORY; import static org.apache.flink.configuration.JobManagerOptions.TOTAL_PROCESS_MEMORY; import static org.apache.flink.configuration.TaskManagerOptions.CPU_CORES; +import static org.apache.flink.runtime.testutils.PseudoRandomValueSelector.randomize; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assume.assumeNoException; import static org.junit.Assume.assumeNotNull; @@ -109,6 +111,28 @@ class PseudoRandomValueSelectorTest { assertThat(uniqueValues).hasSize(1); } + /** + * Tests that randomize() produces different values for different config options within the same + * test. Previously, all boolean options got the same value because the seed did not include the + * config option key. + */ + @Test + void testRandomizeDifferentOptionsProduceDifferentValues() { + final Integer[] alternatives = IntStream.range(0, 20).boxed().toArray(Integer[]::new); + + final Configuration conf = new Configuration(); + final Set<Integer> uniqueValues = new HashSet<>(); + + for (int i = 0; i < 100; i++) { + ConfigOption<Integer> option = + ConfigOptions.key("test.randomize.option." + i).intType().noDefaultValue(); + randomize(conf, option, alternatives); + uniqueValues.add(conf.get(option)); + } + // 100 independent nextInt(20) calls should produce many distinct values + assertThat(uniqueValues).hasSizeGreaterThan(15); + } + /** * Tests that reading through git command yields the same as {@link EnvironmentInformation}. *
