From 0a0bca6f5beb53bca56dea9e60aa49a406e22a61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Mon, 16 Nov 2015 15:08:25 +0100 Subject: [PATCH] Tests: Add unique id to query names to avoid naming conflicts In AbstractQueryTestCase we randomly add the `_name` property to some of the queries. While this generally works, there are exceptional cases where we assign the same name to two queries in the setup which leads to test failures later. This PR adds an increasing counter value to the base tests that gets appended to all random query names to avoid this name clashes. --- .../index/query/AbstractQueryTestCase.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java index 4631036f13d..66cc087135e 100644 --- a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.query; import com.carrotsearch.randomizedtesting.generators.CodepointSetGenerator; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.io.JsonStringEncoder; + import org.apache.lucene.search.BoostQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; @@ -128,6 +129,7 @@ public abstract class AbstractQueryTestCase> private static IndicesQueriesRegistry indicesQueriesRegistry; private static QueryShardContext queryShardContext; private static IndexFieldDataService indexFieldDataService; + private static int queryNameId = 0; protected static QueryShardContext queryShardContext() { @@ -316,12 +318,21 @@ public abstract class AbstractQueryTestCase> query.boost(2.0f / randomIntBetween(1, 20)); } if (randomBoolean()) { - query.queryName(randomAsciiOfLengthBetween(1, 10)); + query.queryName(createUniqueRandomName()); } } return query; } + /** + * make sure query names are unique by suffixing them with increasing counter + */ + private static String createUniqueRandomName() { + String queryName = randomAsciiOfLengthBetween(1, 10) + queryNameId; + queryNameId++; + return queryName; + } + /** * Create the query that is being tested */