From 98700401e92802fd7d33fa7e0b38889c54eec786 Mon Sep 17 00:00:00 2001 From: jimczi Date: Tue, 18 Jun 2019 12:04:09 +0200 Subject: [PATCH] Fix sporadic failures in QueryStringQueryTests#testToQueryFuzzyQueryAutoFuziness This commit ensures that the test does not use reserved keyword (OR, AND, NOT) when generating the random query strings. Closes #43318 --- .../index/query/QueryStringQueryBuilderTests.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java b/server/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java index ad6152e96737f..ddac2be97b1f0 100644 --- a/server/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java @@ -787,25 +787,27 @@ public void testEnabledPositionIncrements() throws Exception { public void testToQueryFuzzyQueryAutoFuziness() throws Exception { 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) @@ -817,7 +819,6 @@ public void testToQueryFuzzyQueryAutoFuziness() throws Exception { } } } - public void testFuzzyNumeric() throws Exception { QueryStringQueryBuilder query = queryStringQuery("12~1.0").defaultField(INT_FIELD_NAME); QueryShardContext context = createShardContext();