Skip to content

Commit c171f9a

Browse files
authored
Fix sporadic failures in QueryStringQueryTests#testToQueryFuzzyQueryAutoFuziness (#43322)
This commit ensures that the test does not use reserved keyword (OR, AND, NOT) when generating the random query strings. Closes #43318
1 parent a3a4bd7 commit c171f9a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

server/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -787,25 +787,27 @@ public void testEnabledPositionIncrements() throws Exception {
787787

788788
public void testToQueryFuzzyQueryAutoFuziness() throws Exception {
789789
for (int i = 0; i < 3; i++) {
790+
final int len;
790791
final int expectedEdits;
791-
String queryString;
792792
switch (i) {
793793
case 0:
794-
queryString = randomAlphaOfLengthBetween(1, 2);
794+
len = randomIntBetween(1, 2);
795795
expectedEdits = 0;
796796
break;
797797

798798
case 1:
799-
queryString = randomAlphaOfLengthBetween(3, 5);
799+
len = randomIntBetween(3, 5);
800800
expectedEdits = 1;
801801
break;
802802

803803
default:
804-
queryString = randomAlphaOfLengthBetween(6, 20);
804+
len = randomIntBetween(6, 20);
805805
expectedEdits = 2;
806806
break;
807807
}
808-
808+
char[] bytes = new char[len];
809+
Arrays.fill(bytes, 'a');
810+
String queryString = new String(bytes);
809811
for (int j = 0; j < 2; j++) {
810812
Query query = queryStringQuery(queryString + (j == 0 ? "~" : "~auto"))
811813
.defaultField(STRING_FIELD_NAME)
@@ -817,7 +819,6 @@ public void testToQueryFuzzyQueryAutoFuziness() throws Exception {
817819
}
818820
}
819821
}
820-
821822
public void testFuzzyNumeric() throws Exception {
822823
QueryStringQueryBuilder query = queryStringQuery("12~1.0").defaultField(INT_FIELD_NAME);
823824
QueryShardContext context = createShardContext();

0 commit comments

Comments
 (0)