Skip to content

Commit 2512a12

Browse files
committed
Fixed flaky test LongFieldMapperTests.testFetchMany test case
1 parent 4e9af10 commit 2512a12

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,6 @@ tests:
498498
- class: org.elasticsearch.search.CCSDuelIT
499499
method: testTermsAggsWithProfile
500500
issue: https://github.com/elastic/elasticsearch/issues/132880
501-
- class: org.elasticsearch.index.mapper.LongFieldMapperTests
502-
method: testFetchMany
503-
issue: https://github.com/elastic/elasticsearch/issues/132948
504501
- class: org.elasticsearch.index.mapper.LongFieldMapperTests
505502
method: testFetch
506503
issue: https://github.com/elastic/elasticsearch/issues/132956

server/src/test/java/org/elasticsearch/index/mapper/LongFieldMapperTests.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
package org.elasticsearch.index.mapper;
1111

1212
import org.elasticsearch.common.bytes.BytesArray;
13+
import org.elasticsearch.datageneration.FieldType;
1314
import org.elasticsearch.script.LongFieldScript;
1415
import org.elasticsearch.script.Script;
1516
import org.elasticsearch.script.ScriptContext;
1617
import org.elasticsearch.xcontent.XContentBuilder;
1718
import org.elasticsearch.xcontent.XContentType;
19+
import org.junit.Before;
1820

1921
import java.io.IOException;
2022
import java.math.BigInteger;
@@ -26,6 +28,15 @@
2628

2729
public class LongFieldMapperTests extends WholeNumberFieldMapperTests {
2830

31+
private FieldType fieldType;
32+
33+
@Before
34+
public void pickNumberType() {
35+
// randomly select between long and double to use for generating random numbers
36+
boolean shouldUseLong = randomBoolean();
37+
fieldType = shouldUseLong ? FieldType.LONG : FieldType.DOUBLE;
38+
}
39+
2940
@Override
3041
protected Number missingValue() {
3142
return 123L;
@@ -45,7 +56,7 @@ protected List<NumberTypeOutOfRangeSpec> outOfRangeSpecs() {
4556

4657
@Override
4758
protected void minimalMapping(XContentBuilder b) throws IOException {
48-
b.field("type", "long");
59+
b.field("type", fieldType.toString());
4960
}
5061

5162
@Override
@@ -105,7 +116,8 @@ public void testLongIndexingCoercesIntoRange() throws Exception {
105116

106117
@Override
107118
protected Number randomNumber() {
108-
if (randomBoolean()) {
119+
// we must be consistent with the type of each number that we generate
120+
if (fieldType.equals(FieldType.LONG)) {
109121
return randomLong();
110122
}
111123
if (randomBoolean()) {

0 commit comments

Comments
 (0)