Skip to content

Commit

Permalink
Fix sporadic failures in QueryStringQueryTests#testToQueryFuzzyQueryA…
Browse files Browse the repository at this point in the history
…utoFuziness (#43322) (#51531)

This commit ensures that the test does not use reserved keyword (OR, AND, NOT)
when generating the random query strings.

Backport of #43322

Co-authored-by: Jim Ferenczi <[email protected]>
  • Loading branch information
Christoph Büscher and jimczi authored Jan 28, 2020
1 parent f86c1bc commit 8a28c8d
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -776,25 +776,27 @@ public void testEnabledPositionIncrements() throws Exception {
public void testToQueryFuzzyQueryAutoFuziness() throws Exception {
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
for (int i = 0; i < 3; i++) {
final int len;
final int expectedEdits;
String queryString;
switch (i) {
case 0:
queryString = randomAlphaOfLengthBetween(1, 2);
len = randomIntBetween(1, 2);
expectedEdits = 0;
break;

case 1:
queryString = randomAlphaOfLengthBetween(3, 5);
len = randomIntBetween(3, 5);
expectedEdits = 1;
break;

default:
queryString = randomAlphaOfLengthBetween(6, 20);
len = randomIntBetween(6, 20);
expectedEdits = 2;
break;
}

char[] bytes = new char[len];
Arrays.fill(bytes, 'a');
String queryString = new String(bytes);
for (int j = 0; j < 2; j++) {
Query query = queryStringQuery(queryString + (j == 0 ? "~" : "~auto"))
.defaultField(STRING_FIELD_NAME)
Expand All @@ -806,7 +808,6 @@ public void testToQueryFuzzyQueryAutoFuziness() throws Exception {
}
}
}

public void testFuzzyNumeric() throws Exception {
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
QueryStringQueryBuilder query = queryStringQuery("12~0.2").defaultField(INT_FIELD_NAME);
Expand Down

0 comments on commit 8a28c8d

Please sign in to comment.