Skip to content

Commit 2971aa1

Browse files
kasundra07shiv0408
authored andcommitted
Fixing the tests for concurrent search (opensearch-project#11076)
* Fixing the tests for concurrent search Signed-off-by: Bansi Kasundra <kasundra@amazon.com> * Remove changes for non-flaky tests Signed-off-by: Bansi Kasundra <kasundra@amazon.com> --------- Signed-off-by: Bansi Kasundra <kasundra@amazon.com> Signed-off-by: Shivansh Arora <hishiv@amazon.com>
1 parent fcccd07 commit 2971aa1

File tree

3 files changed

+74
-23
lines changed

3 files changed

+74
-23
lines changed

server/src/internalClusterTest/java/org/opensearch/search/fetch/subphase/InnerHitsIT.java

+4
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ public void testNestedSource() throws Exception {
897897
)
898898
.get();
899899
refresh();
900+
indexRandomForConcurrentSearch("index1");
900901

901902
// the field name (comments.message) used for source filtering should be the same as when using that field for
902903
// other features (like in the query dsl or aggs) in order for consistency:
@@ -973,6 +974,7 @@ public void testInnerHitsWithIgnoreUnmapped() throws Exception {
973974
client().prepareIndex("index1").setId("1").setSource("nested_type", Collections.singletonMap("key", "value")).get();
974975
client().prepareIndex("index2").setId("3").setSource("key", "value").get();
975976
refresh();
977+
indexRandomForConcurrentSearch("index1", "index2");
976978

977979
SearchResponse response = client().prepareSearch("index1", "index2")
978980
.setQuery(
@@ -1002,6 +1004,7 @@ public void testUseMaxDocInsteadOfSize() throws Exception {
10021004
.setRefreshPolicy(IMMEDIATE)
10031005
.get();
10041006

1007+
indexRandomForConcurrentSearch("index2");
10051008
QueryBuilder query = nestedQuery("nested", matchQuery("nested.field", "value1"), ScoreMode.Avg).innerHit(
10061009
new InnerHitBuilder().setSize(ArrayUtil.MAX_ARRAY_LENGTH - 1)
10071010
);
@@ -1019,6 +1022,7 @@ public void testTooHighResultWindow() throws Exception {
10191022
)
10201023
.setRefreshPolicy(IMMEDIATE)
10211024
.get();
1025+
indexRandomForConcurrentSearch("index2");
10221026
SearchResponse response = client().prepareSearch("index2")
10231027
.setQuery(
10241028
nestedQuery("nested", matchQuery("nested.field", "value1"), ScoreMode.Avg).innerHit(

server/src/internalClusterTest/java/org/opensearch/search/fetch/subphase/MatchedQueriesIT.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public void testSimpleMatchedQueryFromFilteredQuery() throws Exception {
9191
client().prepareIndex("test").setId("2").setSource("name", "test2", "number", 2).get();
9292
client().prepareIndex("test").setId("3").setSource("name", "test3", "number", 3).get();
9393
refresh();
94+
indexRandomForConcurrentSearch("test");
9495

9596
SearchResponse searchResponse = client().prepareSearch()
9697
.setQuery(
@@ -141,6 +142,7 @@ public void testSimpleMatchedQueryFromTopLevelFilter() throws Exception {
141142
client().prepareIndex("test").setId("2").setSource("name", "test").get();
142143
client().prepareIndex("test").setId("3").setSource("name", "test").get();
143144
refresh();
145+
indexRandomForConcurrentSearch("test");
144146

145147
SearchResponse searchResponse = client().prepareSearch()
146148
.setQuery(matchAllQuery())
@@ -192,6 +194,7 @@ public void testSimpleMatchedQueryFromTopLevelFilterAndFilteredQuery() throws Ex
192194
client().prepareIndex("test").setId("2").setSource("name", "test", "title", "title2").get();
193195
client().prepareIndex("test").setId("3").setSource("name", "test", "title", "title3").get();
194196
refresh();
197+
indexRandomForConcurrentSearch("test");
195198

196199
SearchResponse searchResponse = client().prepareSearch()
197200
.setQuery(boolQuery().must(matchAllQuery()).filter(termsQuery("title", "title1", "title2", "title3").queryName("title")))
@@ -224,12 +227,13 @@ public void testSimpleMatchedQueryFromTopLevelFilterAndFilteredQuery() throws Ex
224227
}
225228
}
226229

227-
public void testRegExpQuerySupportsName() {
230+
public void testRegExpQuerySupportsName() throws InterruptedException {
228231
createIndex("test1");
229232
ensureGreen();
230233

231234
client().prepareIndex("test1").setId("1").setSource("title", "title1").get();
232235
refresh();
236+
indexRandomForConcurrentSearch("test1");
233237

234238
SearchResponse searchResponse = client().prepareSearch()
235239
.setQuery(QueryBuilders.regexpQuery("title", "title1").queryName("regex"))
@@ -246,12 +250,13 @@ public void testRegExpQuerySupportsName() {
246250
}
247251
}
248252

249-
public void testPrefixQuerySupportsName() {
253+
public void testPrefixQuerySupportsName() throws InterruptedException {
250254
createIndex("test1");
251255
ensureGreen();
252256

253257
client().prepareIndex("test1").setId("1").setSource("title", "title1").get();
254258
refresh();
259+
indexRandomForConcurrentSearch("test1");
255260

256261
SearchResponse searchResponse = client().prepareSearch()
257262
.setQuery(QueryBuilders.prefixQuery("title", "title").queryName("prefix"))
@@ -268,12 +273,13 @@ public void testPrefixQuerySupportsName() {
268273
}
269274
}
270275

271-
public void testFuzzyQuerySupportsName() {
276+
public void testFuzzyQuerySupportsName() throws InterruptedException {
272277
createIndex("test1");
273278
ensureGreen();
274279

275280
client().prepareIndex("test1").setId("1").setSource("title", "title1").get();
276281
refresh();
282+
indexRandomForConcurrentSearch("test1");
277283

278284
SearchResponse searchResponse = client().prepareSearch()
279285
.setQuery(QueryBuilders.fuzzyQuery("title", "titel1").queryName("fuzzy"))
@@ -290,12 +296,13 @@ public void testFuzzyQuerySupportsName() {
290296
}
291297
}
292298

293-
public void testWildcardQuerySupportsName() {
299+
public void testWildcardQuerySupportsName() throws InterruptedException {
294300
createIndex("test1");
295301
ensureGreen();
296302

297303
client().prepareIndex("test1").setId("1").setSource("title", "title1").get();
298304
refresh();
305+
indexRandomForConcurrentSearch("test1");
299306

300307
SearchResponse searchResponse = client().prepareSearch()
301308
.setQuery(QueryBuilders.wildcardQuery("title", "titl*").queryName("wildcard"))
@@ -312,12 +319,13 @@ public void testWildcardQuerySupportsName() {
312319
}
313320
}
314321

315-
public void testSpanFirstQuerySupportsName() {
322+
public void testSpanFirstQuerySupportsName() throws InterruptedException {
316323
createIndex("test1");
317324
ensureGreen();
318325

319326
client().prepareIndex("test1").setId("1").setSource("title", "title1 title2").get();
320327
refresh();
328+
indexRandomForConcurrentSearch("test1");
321329

322330
SearchResponse searchResponse = client().prepareSearch()
323331
.setQuery(QueryBuilders.spanFirstQuery(QueryBuilders.spanTermQuery("title", "title1"), 10).queryName("span"))
@@ -344,6 +352,7 @@ public void testMatchedWithShould() throws Exception {
344352
client().prepareIndex("test").setId("1").setSource("content", "Lorem ipsum dolor sit amet").get();
345353
client().prepareIndex("test").setId("2").setSource("content", "consectetur adipisicing elit").get();
346354
refresh();
355+
indexRandomForConcurrentSearch("test");
347356

348357
// Execute search at least two times to load it in cache
349358
int iter = scaledRandomIntBetween(2, 10);
@@ -378,6 +387,7 @@ public void testMatchedWithWrapperQuery() throws Exception {
378387

379388
client().prepareIndex("test").setId("1").setSource("content", "Lorem ipsum dolor sit amet").get();
380389
refresh();
390+
indexRandomForConcurrentSearch("test");
381391

382392
MatchQueryBuilder matchQueryBuilder = matchQuery("content", "amet").queryName("abc");
383393
BytesReference matchBytes = XContentHelper.toXContent(matchQueryBuilder, MediaTypeRegistry.JSON, false);

0 commit comments

Comments
 (0)