Skip to content

Commit 57f6908

Browse files
authored
Disable cache on QueryProfilerIT (elastic#38748)
- Disables the request cache on the test, to prevent cached values from potentially interfering with test results - Changes the test to execute a single query, in hopes of making failures more reproducible Backport of elastic#38583
1 parent a3f3974 commit 57f6908

File tree

1 file changed

+56
-57
lines changed

1 file changed

+56
-57
lines changed

server/src/test/java/org/elasticsearch/search/profile/query/QueryProfilerIT.java

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,10 @@ public void testProfileQuery() throws Exception {
105105
}
106106

107107
/**
108-
* This test generates 1-10 random queries and executes a profiled and non-profiled
108+
* This test generates a random query and executes a profiled and non-profiled
109109
* search for each query. It then does some basic sanity checking of score and hits
110110
* to make sure the profiling doesn't interfere with the hits being returned
111111
*/
112-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/32492")
113112
public void testProfileMatchesRegular() throws Exception {
114113
createIndex("test");
115114
ensureGreen();
@@ -129,68 +128,68 @@ public void testProfileMatchesRegular() throws Exception {
129128
indexRandom(true, docs);
130129

131130
refresh();
132-
int iters = between(1, 10);
133-
for (int i = 0; i < iters; i++) {
134-
QueryBuilder q = randomQueryBuilder(stringFields, numericFields, numDocs, 3);
135-
logger.info("Query: {}", q);
136-
137-
SearchRequestBuilder vanilla = client().prepareSearch("test")
138-
.setQuery(q)
139-
.setProfile(false)
140-
.addSort("_id", SortOrder.ASC)
141-
.setSearchType(SearchType.QUERY_THEN_FETCH);
131+
QueryBuilder q = randomQueryBuilder(stringFields, numericFields, numDocs, 3);
132+
logger.debug("Query: {}", q);
133+
134+
SearchRequestBuilder vanilla = client().prepareSearch("test")
135+
.setQuery(q)
136+
.setProfile(false)
137+
.addSort("_id", SortOrder.ASC)
138+
.setSearchType(SearchType.QUERY_THEN_FETCH)
139+
.setRequestCache(false);
140+
141+
SearchRequestBuilder profile = client().prepareSearch("test")
142+
.setQuery(q)
143+
.setProfile(true)
144+
.addSort("_id", SortOrder.ASC)
145+
.setSearchType(SearchType.QUERY_THEN_FETCH)
146+
.setRequestCache(false);
147+
148+
MultiSearchResponse.Item[] responses = client().prepareMultiSearch()
149+
.add(vanilla)
150+
.add(profile)
151+
.get().getResponses();
152+
153+
SearchResponse vanillaResponse = responses[0].getResponse();
154+
SearchResponse profileResponse = responses[1].getResponse();
155+
156+
assertThat(vanillaResponse.getFailedShards(), equalTo(0));
157+
assertThat(profileResponse.getFailedShards(), equalTo(0));
158+
assertThat(vanillaResponse.getSuccessfulShards(), equalTo(profileResponse.getSuccessfulShards()));
159+
160+
float vanillaMaxScore = vanillaResponse.getHits().getMaxScore();
161+
float profileMaxScore = profileResponse.getHits().getMaxScore();
162+
if (Float.isNaN(vanillaMaxScore)) {
163+
assertTrue("Vanilla maxScore is NaN but Profile is not [" + profileMaxScore + "]",
164+
Float.isNaN(profileMaxScore));
165+
} else {
166+
assertEquals("Profile maxScore of [" + profileMaxScore + "] is not close to Vanilla maxScore [" + vanillaMaxScore + "]",
167+
vanillaMaxScore, profileMaxScore, 0.001);
168+
}
142169

143-
SearchRequestBuilder profile = client().prepareSearch("test")
144-
.setQuery(q)
145-
.setProfile(true)
146-
.addSort("_id", SortOrder.ASC)
147-
.setSearchType(SearchType.QUERY_THEN_FETCH);
148-
149-
MultiSearchResponse.Item[] responses = client().prepareMultiSearch()
150-
.add(vanilla)
151-
.add(profile)
152-
.get().getResponses();
153-
154-
SearchResponse vanillaResponse = responses[0].getResponse();
155-
SearchResponse profileResponse = responses[1].getResponse();
156-
157-
assertThat(vanillaResponse.getFailedShards(), equalTo(0));
158-
assertThat(profileResponse.getFailedShards(), equalTo(0));
159-
assertThat(vanillaResponse.getSuccessfulShards(), equalTo(profileResponse.getSuccessfulShards()));
160-
161-
float vanillaMaxScore = vanillaResponse.getHits().getMaxScore();
162-
float profileMaxScore = profileResponse.getHits().getMaxScore();
163-
if (Float.isNaN(vanillaMaxScore)) {
164-
assertTrue("Vanilla maxScore is NaN but Profile is not [" + profileMaxScore + "]",
165-
Float.isNaN(profileMaxScore));
170+
if (vanillaResponse.getHits().getTotalHits().value != profileResponse.getHits().getTotalHits().value) {
171+
Set<SearchHit> vanillaSet = new HashSet<>(Arrays.asList(vanillaResponse.getHits().getHits()));
172+
Set<SearchHit> profileSet = new HashSet<>(Arrays.asList(profileResponse.getHits().getHits()));
173+
if (vanillaResponse.getHits().getTotalHits().value > profileResponse.getHits().getTotalHits().value) {
174+
vanillaSet.removeAll(profileSet);
175+
fail("Vanilla hits were larger than profile hits. Non-overlapping elements were: "
176+
+ vanillaSet.toString());
166177
} else {
167-
assertEquals("Profile maxScore of [" + profileMaxScore + "] is not close to Vanilla maxScore [" + vanillaMaxScore + "]",
168-
vanillaMaxScore, profileMaxScore, 0.001);
178+
profileSet.removeAll(vanillaSet);
179+
fail("Profile hits were larger than vanilla hits. Non-overlapping elements were: "
180+
+ profileSet.toString());
169181
}
182+
}
170183

171-
if (vanillaResponse.getHits().getTotalHits().value != profileResponse.getHits().getTotalHits().value) {
172-
Set<SearchHit> vanillaSet = new HashSet<>(Arrays.asList(vanillaResponse.getHits().getHits()));
173-
Set<SearchHit> profileSet = new HashSet<>(Arrays.asList(profileResponse.getHits().getHits()));
174-
if (vanillaResponse.getHits().getTotalHits().value > profileResponse.getHits().getTotalHits().value) {
175-
vanillaSet.removeAll(profileSet);
176-
fail("Vanilla hits were larger than profile hits. Non-overlapping elements were: "
177-
+ vanillaSet.toString());
178-
} else {
179-
profileSet.removeAll(vanillaSet);
180-
fail("Profile hits were larger than vanilla hits. Non-overlapping elements were: "
181-
+ profileSet.toString());
182-
}
183-
}
184+
SearchHit[] vanillaHits = vanillaResponse.getHits().getHits();
185+
SearchHit[] profileHits = profileResponse.getHits().getHits();
184186

185-
SearchHit[] vanillaHits = vanillaResponse.getHits().getHits();
186-
SearchHit[] profileHits = profileResponse.getHits().getHits();
187+
for (int j = 0; j < vanillaHits.length; j++) {
188+
assertThat("Profile hit #" + j + " has a different ID from Vanilla",
189+
vanillaHits[j].getId(), equalTo(profileHits[j].getId()));
190+
}
187191

188-
for (int j = 0; j < vanillaHits.length; j++) {
189-
assertThat("Profile hit #" + j + " has a different ID from Vanilla",
190-
vanillaHits[j].getId(), equalTo(profileHits[j].getId()));
191-
}
192192

193-
}
194193
}
195194

196195
/**

0 commit comments

Comments
 (0)