Skip to content

Commit bf557fd

Browse files
authored
test: avoid generating duplicate multiple fields (#27080)
Multifields parser does not allow duplicate values, however the MultiFieldTests may produce duplicate field values. See https://elasticsearch-ci.elastic.co/job/elastic+elasticsearch+master+release-tests/132/console.
1 parent d0104c2 commit bf557fd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

core/src/test/java/org/elasticsearch/index/mapper/MultiFieldTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535

3636
import java.io.IOException;
3737
import java.util.Arrays;
38+
import java.util.HashSet;
3839
import java.util.Map;
40+
import java.util.Set;
3941

4042
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
4143
import static org.elasticsearch.test.StreamsUtils.copyToBytesFromClasspath;
@@ -155,8 +157,9 @@ public void testBuildThenParse() throws Exception {
155157
// can to unnecessary re-syncing of the mappings between the local instance and cluster state
156158
public void testMultiFieldsInConsistentOrder() throws Exception {
157159
String[] multiFieldNames = new String[randomIntBetween(2, 10)];
160+
Set<String> seenFields = new HashSet<>();
158161
for (int i = 0; i < multiFieldNames.length; i++) {
159-
multiFieldNames[i] = randomAlphaOfLength(4);
162+
multiFieldNames[i] = randomValueOtherThanMany(s -> !seenFields.add(s), () -> randomAlphaOfLength(4));
160163
}
161164

162165
XContentBuilder builder = jsonBuilder().startObject().startObject("type").startObject("properties")

0 commit comments

Comments
 (0)