Skip to content

Commit 4ccba11

Browse files
ticheng-awsshiv0408
authored andcommitted
Fixing concurrent search tests with one slice (opensearch-project#11071)
* Fixing concurrent search tests with one slice (opensearch-project#11071) Signed-off-by: Ticheng Lin <ticheng@amazon.com> * Remove changes for non-flaky tests (opensearch-project#11071) Signed-off-by: Ticheng Lin <ticheng@amazon.com> --------- Signed-off-by: Ticheng Lin <ticheng@amazon.com> Signed-off-by: Shivansh Arora <hishiv@amazon.com>
1 parent 4bb0377 commit 4ccba11

File tree

6 files changed

+45
-9
lines changed

6 files changed

+45
-9
lines changed

server/src/internalClusterTest/java/org/opensearch/search/nested/SimpleNestedIT.java

+8
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ public void testMultiNested() throws Exception {
293293
refresh();
294294
// check the numDocs
295295
assertDocumentCount("test", 7);
296+
indexRandomForConcurrentSearch("test");
296297

297298
// do some multi nested queries
298299
SearchResponse searchResponse = client().prepareSearch("test")
@@ -485,6 +486,7 @@ public void testExplain() throws Exception {
485486
)
486487
.setRefreshPolicy(IMMEDIATE)
487488
.get();
489+
indexRandomForConcurrentSearch("test");
488490

489491
SearchResponse searchResponse = client().prepareSearch("test")
490492
.setQuery(nestedQuery("nested1", termQuery("nested1.n_field1", "n_value1"), ScoreMode.Total))
@@ -968,6 +970,10 @@ public void testNestedSortWithMultiLevelFiltering() throws Exception {
968970

969971
// https://github.com/elastic/elasticsearch/issues/31554
970972
public void testLeakingSortValues() throws Exception {
973+
assumeFalse(
974+
"Concurrent search case muted pending fix: https://github.com/opensearch-project/OpenSearch/issues/11065",
975+
internalCluster().clusterService().getClusterSettings().get(CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING)
976+
);
971977
assertAcked(
972978
prepareCreate("test").setSettings(Settings.builder().put("number_of_shards", 1))
973979
.setMapping(
@@ -1035,6 +1041,7 @@ public void testLeakingSortValues() throws Exception {
10351041
.get();
10361042

10371043
refresh();
1044+
indexRandomForConcurrentSearch("test");
10381045

10391046
SearchResponse searchResponse = client().prepareSearch()
10401047
.setQuery(termQuery("_id", 2))
@@ -1627,6 +1634,7 @@ public void testCheckFixedBitSetCache() throws Exception {
16271634
client().prepareIndex("test").setId("1").setSource("field", "value").get();
16281635
refresh();
16291636
ensureSearchable("test");
1637+
indexRandomForConcurrentSearch("test");
16301638

16311639
// No nested mapping yet, there shouldn't be anything in the fixed bit set cache
16321640
ClusterStatsResponse clusterStatsResponse = client().admin().cluster().prepareClusterStats().get();

server/src/internalClusterTest/java/org/opensearch/search/pit/PitMultiNodeIT.java

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public void clearIndex() {
100100
public void testPit() throws Exception {
101101
CreatePitRequest request = new CreatePitRequest(TimeValue.timeValueDays(1), true);
102102
request.setIndices(new String[] { "index" });
103+
indexRandomForConcurrentSearch("index");
103104
ActionFuture<CreatePitResponse> execute = client().execute(CreatePitAction.INSTANCE, request);
104105
CreatePitResponse pitResponse = execute.get();
105106
SearchResponse searchResponse = client().prepareSearch("index")

server/src/internalClusterTest/java/org/opensearch/search/preference/SearchPreferenceIT.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import org.opensearch.test.OpenSearchIntegTestCase;
5353
import org.opensearch.test.ParameterizedOpenSearchIntegTestCase;
5454

55-
import java.io.IOException;
5655
import java.util.ArrayList;
5756
import java.util.Arrays;
5857
import java.util.Collection;
@@ -99,7 +98,7 @@ public Settings nodeSettings(int nodeOrdinal) {
9998
}
10099

101100
// see #2896
102-
public void testStopOneNodePreferenceWithRedState() throws IOException {
101+
public void testStopOneNodePreferenceWithRedState() throws Exception {
103102
assertAcked(
104103
prepareCreate("test").setSettings(
105104
Settings.builder().put("index.number_of_shards", cluster().numDataNodes() + 2).put("index.number_of_replicas", 0)
@@ -110,6 +109,7 @@ public void testStopOneNodePreferenceWithRedState() throws IOException {
110109
client().prepareIndex("test").setId("" + i).setSource("field1", "value1").get();
111110
}
112111
refresh();
112+
indexRandomForConcurrentSearch("test");
113113
internalCluster().stopRandomDataNode();
114114
client().admin().cluster().prepareHealth().setWaitForStatus(ClusterHealthStatus.RED).get();
115115
String[] preferences = new String[] {
@@ -138,7 +138,7 @@ public void testStopOneNodePreferenceWithRedState() throws IOException {
138138
assertThat("_only_local", searchResponse.getFailedShards(), greaterThanOrEqualTo(0));
139139
}
140140

141-
public void testNoPreferenceRandom() {
141+
public void testNoPreferenceRandom() throws Exception {
142142
assertAcked(
143143
prepareCreate("test").setSettings(
144144
// this test needs at least a replica to make sure two consecutive searches go to two different copies of the same data
@@ -149,6 +149,7 @@ public void testNoPreferenceRandom() {
149149

150150
client().prepareIndex("test").setSource("field1", "value1").get();
151151
refresh();
152+
indexRandomForConcurrentSearch("test");
152153

153154
final Client client = internalCluster().smartClient();
154155
SearchResponse searchResponse = client.prepareSearch("test").setQuery(matchAllQuery()).get();
@@ -201,7 +202,7 @@ public void testThatSpecifyingNonExistingNodesReturnsUsefulError() {
201202
}
202203
}
203204

204-
public void testNodesOnlyRandom() {
205+
public void testNodesOnlyRandom() throws Exception {
205206
assertAcked(
206207
prepareCreate("test").setSettings(
207208
// this test needs at least a replica to make sure two consecutive searches go to two different copies of the same data
@@ -211,6 +212,7 @@ public void testNodesOnlyRandom() {
211212
ensureGreen();
212213
client().prepareIndex("test").setSource("field1", "value1").get();
213214
refresh();
215+
indexRandomForConcurrentSearch("test");
214216

215217
final Client client = internalCluster().smartClient();
216218
// multiple wildchar to cover multi-param usecase

server/src/internalClusterTest/java/org/opensearch/search/query/QueryStringIT.java

+6
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ public void testDocWithAllTypes() throws Exception {
186186
String docBody = copyToStringFromClasspath("/org/opensearch/search/query/all-example-document.json");
187187
reqs.add(client().prepareIndex("test").setId("1").setSource(docBody, MediaTypeRegistry.JSON));
188188
indexRandom(true, false, reqs);
189+
indexRandomForConcurrentSearch("test");
189190

190191
SearchResponse resp = client().prepareSearch("test").setQuery(queryStringQuery("foo")).get();
191192
assertHits(resp.getHits(), "1");
@@ -225,6 +226,7 @@ public void testKeywordWithWhitespace() throws Exception {
225226
reqs.add(client().prepareIndex("test").setId("2").setSource("f1", "bar"));
226227
reqs.add(client().prepareIndex("test").setId("3").setSource("f1", "foo bar"));
227228
indexRandom(true, false, reqs);
229+
indexRandomForConcurrentSearch("test");
228230

229231
SearchResponse resp = client().prepareSearch("test").setQuery(queryStringQuery("foo")).get();
230232
assertHits(resp.getHits(), "3");
@@ -245,6 +247,7 @@ public void testRegexCaseInsensitivity() throws Exception {
245247
indexRequests.add(client().prepareIndex("messages").setId("1").setSource("message", "message: this is a TLS handshake"));
246248
indexRequests.add(client().prepareIndex("messages").setId("2").setSource("message", "message: this is a tcp handshake"));
247249
indexRandom(true, false, indexRequests);
250+
indexRandomForConcurrentSearch("messages");
248251

249252
SearchResponse response = client().prepareSearch("messages").setQuery(queryStringQuery("/TLS/").defaultField("message")).get();
250253
assertNoFailures(response);
@@ -282,6 +285,7 @@ public void testAllFields() throws Exception {
282285
List<IndexRequestBuilder> reqs = new ArrayList<>();
283286
reqs.add(client().prepareIndex("test_1").setId("1").setSource("f1", "foo", "f2", "eggplant"));
284287
indexRandom(true, false, reqs);
288+
indexRandomForConcurrentSearch("test_1");
285289

286290
SearchResponse resp = client().prepareSearch("test_1")
287291
.setQuery(queryStringQuery("foo eggplant").defaultOperator(Operator.AND))
@@ -374,6 +378,7 @@ public void testLimitOnExpandedFields() throws Exception {
374378

375379
client().prepareIndex("testindex").setId("1").setSource("field_A0", "foo bar baz").get();
376380
refresh();
381+
indexRandomForConcurrentSearch("testindex");
377382

378383
// single field shouldn't trigger the limit
379384
doAssertOneHitForQueryString("field_A0:foo");
@@ -465,6 +470,7 @@ public void testFieldAliasOnDisallowedFieldType() throws Exception {
465470
List<IndexRequestBuilder> indexRequests = new ArrayList<>();
466471
indexRequests.add(client().prepareIndex("test").setId("1").setSource("f3", "text", "f2", "one"));
467472
indexRandom(true, false, indexRequests);
473+
indexRandomForConcurrentSearch("test");
468474

469475
// The wildcard field matches aliases for both a text and geo_point field.
470476
// By default, the geo_point field should be ignored when building the query.

server/src/internalClusterTest/java/org/opensearch/search/query/ScriptScoreQueryIT.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,14 @@ protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
109109
// 1) only matched docs retrieved
110110
// 2) score is calculated based on a script with params
111111
// 3) min score applied
112-
public void testScriptScore() {
112+
public void testScriptScore() throws Exception {
113113
assertAcked(prepareCreate("test-index").setMapping("field1", "type=text", "field2", "type=double"));
114114
int docCount = 10;
115115
for (int i = 1; i <= docCount; i++) {
116116
client().prepareIndex("test-index").setId("" + i).setSource("field1", "text" + (i % 2), "field2", i).get();
117117
}
118118
refresh();
119+
indexRandomForConcurrentSearch("test-index");
119120

120121
Map<String, Object> params = new HashMap<>();
121122
params.put("param1", 0.1);
@@ -135,13 +136,14 @@ public void testScriptScore() {
135136
assertOrderedSearchHits(resp, "10", "8", "6");
136137
}
137138

138-
public void testScriptScoreBoolQuery() {
139+
public void testScriptScoreBoolQuery() throws Exception {
139140
assertAcked(prepareCreate("test-index").setMapping("field1", "type=text", "field2", "type=double"));
140141
int docCount = 10;
141142
for (int i = 1; i <= docCount; i++) {
142143
client().prepareIndex("test-index").setId("" + i).setSource("field1", "text" + i, "field2", i).get();
143144
}
144145
refresh();
146+
indexRandomForConcurrentSearch("test-index");
145147

146148
Map<String, Object> params = new HashMap<>();
147149
params.put("param1", 0.1);
@@ -155,7 +157,7 @@ public void testScriptScoreBoolQuery() {
155157
}
156158

157159
// test that when the internal query is rewritten script_score works well
158-
public void testRewrittenQuery() {
160+
public void testRewrittenQuery() throws Exception {
159161
assertAcked(
160162
prepareCreate("test-index2").setSettings(Settings.builder().put("index.number_of_shards", 1))
161163
.setMapping("field1", "type=date", "field2", "type=double")
@@ -164,6 +166,7 @@ public void testRewrittenQuery() {
164166
client().prepareIndex("test-index2").setId("2").setSource("field1", "2019-10-01", "field2", 2).get();
165167
client().prepareIndex("test-index2").setId("3").setSource("field1", "2019-11-01", "field2", 3).get();
166168
refresh();
169+
indexRandomForConcurrentSearch("test-index2");
167170

168171
RangeQueryBuilder rangeQB = new RangeQueryBuilder("field1").from("2019-01-01"); // the query should be rewritten to from:null
169172
Map<String, Object> params = new HashMap<>();
@@ -174,14 +177,15 @@ public void testRewrittenQuery() {
174177
assertOrderedSearchHits(resp, "3", "2", "1");
175178
}
176179

177-
public void testDisallowExpensiveQueries() {
180+
public void testDisallowExpensiveQueries() throws Exception {
178181
try {
179182
assertAcked(prepareCreate("test-index").setMapping("field1", "type=text", "field2", "type=double"));
180183
int docCount = 10;
181184
for (int i = 1; i <= docCount; i++) {
182185
client().prepareIndex("test-index").setId("" + i).setSource("field1", "text" + (i % 2), "field2", i).get();
183186
}
184187
refresh();
188+
indexRandomForConcurrentSearch("test-index");
185189

186190
Map<String, Object> params = new HashMap<>();
187191
params.put("param1", 0.1);

server/src/internalClusterTest/java/org/opensearch/search/query/SimpleQueryStringIT.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public void testSimpleQueryString() throws ExecutionException, InterruptedExcept
150150
client().prepareIndex("test").setId("5").setSource("body", "quux baz spaghetti"),
151151
client().prepareIndex("test").setId("6").setSource("otherbody", "spaghetti")
152152
);
153+
indexRandomForConcurrentSearch("test");
153154

154155
SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("foo bar")).get();
155156
assertHitCount(searchResponse, 3L);
@@ -199,6 +200,7 @@ public void testSimpleQueryStringMinimumShouldMatch() throws Exception {
199200
client().prepareIndex("test").setId("3").setSource("body", "foo bar"),
200201
client().prepareIndex("test").setId("4").setSource("body", "foo baz bar")
201202
);
203+
indexRandomForConcurrentSearch("test");
202204

203205
logger.info("--> query 1");
204206
SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("foo bar").minimumShouldMatch("2")).get();
@@ -235,6 +237,7 @@ public void testSimpleQueryStringMinimumShouldMatch() throws Exception {
235237
client().prepareIndex("test").setId("7").setSource("body2", "foo bar", "other", "foo"),
236238
client().prepareIndex("test").setId("8").setSource("body2", "foo baz bar", "other", "foo")
237239
);
240+
indexRandomForConcurrentSearch("test");
238241

239242
logger.info("--> query 5");
240243
searchResponse = client().prepareSearch()
@@ -256,7 +259,7 @@ public void testSimpleQueryStringMinimumShouldMatch() throws Exception {
256259
assertSearchHits(searchResponse, "6", "7", "8");
257260
}
258261

259-
public void testNestedFieldSimpleQueryString() throws IOException {
262+
public void testNestedFieldSimpleQueryString() throws Exception {
260263
assertAcked(
261264
prepareCreate("test").setMapping(
262265
jsonBuilder().startObject()
@@ -275,6 +278,7 @@ public void testNestedFieldSimpleQueryString() throws IOException {
275278
);
276279
client().prepareIndex("test").setId("1").setSource("body", "foo bar baz").get();
277280
refresh();
281+
indexRandomForConcurrentSearch("test");
278282

279283
SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("foo bar baz").field("body")).get();
280284
assertHitCount(searchResponse, 1L);
@@ -359,6 +363,8 @@ public void testSimpleQueryStringLenient() throws ExecutionException, Interrupte
359363
client().prepareIndex("test2").setId("10").setSource("field", 5)
360364
);
361365
refresh();
366+
indexRandomForConcurrentSearch("test1");
367+
indexRandomForConcurrentSearch("test2");
362368

363369
SearchResponse searchResponse = client().prepareSearch()
364370
.setAllowPartialSearchResults(true)
@@ -419,6 +425,7 @@ public void testSimpleQueryStringUsesFieldAnalyzer() throws Exception {
419425
client().prepareIndex("test").setId("2").setSource("foo", 234, "bar", "bcd").get();
420426

421427
refresh();
428+
indexRandomForConcurrentSearch("test");
422429

423430
SearchResponse searchResponse = client().prepareSearch().setQuery(simpleQueryStringQuery("123").field("foo").field("bar")).get();
424431
assertHitCount(searchResponse, 1L);
@@ -469,6 +476,7 @@ public void testBasicAllQuery() throws Exception {
469476
reqs.add(client().prepareIndex("test").setId("2").setSource("f2", "Bar"));
470477
reqs.add(client().prepareIndex("test").setId("3").setSource("f3", "foo bar baz"));
471478
indexRandom(true, false, reqs);
479+
indexRandomForConcurrentSearch("test");
472480

473481
SearchResponse resp = client().prepareSearch("test").setQuery(simpleQueryStringQuery("foo")).get();
474482
assertHitCount(resp, 2L);
@@ -492,6 +500,7 @@ public void testWithDate() throws Exception {
492500
reqs.add(client().prepareIndex("test").setId("1").setSource("f1", "foo", "f_date", "2015/09/02"));
493501
reqs.add(client().prepareIndex("test").setId("2").setSource("f1", "bar", "f_date", "2015/09/01"));
494502
indexRandom(true, false, reqs);
503+
indexRandomForConcurrentSearch("test");
495504

496505
SearchResponse resp = client().prepareSearch("test").setQuery(simpleQueryStringQuery("foo bar")).get();
497506
assertHits(resp.getHits(), "1", "2");
@@ -523,6 +532,7 @@ public void testWithLotsOfTypes() throws Exception {
523532
client().prepareIndex("test").setId("2").setSource("f1", "bar", "f_date", "2015/09/01", "f_float", "1.8", "f_ip", "127.0.0.2")
524533
);
525534
indexRandom(true, false, reqs);
535+
indexRandomForConcurrentSearch("test");
526536

527537
SearchResponse resp = client().prepareSearch("test").setQuery(simpleQueryStringQuery("foo bar")).get();
528538
assertHits(resp.getHits(), "1", "2");
@@ -550,6 +560,7 @@ public void testDocWithAllTypes() throws Exception {
550560
String docBody = copyToStringFromClasspath("/org/opensearch/search/query/all-example-document.json");
551561
reqs.add(client().prepareIndex("test").setId("1").setSource(docBody, MediaTypeRegistry.JSON));
552562
indexRandom(true, false, reqs);
563+
indexRandomForConcurrentSearch("test");
553564

554565
SearchResponse resp = client().prepareSearch("test").setQuery(simpleQueryStringQuery("foo")).get();
555566
assertHits(resp.getHits(), "1");
@@ -596,6 +607,7 @@ public void testKeywordWithWhitespace() throws Exception {
596607
reqs.add(client().prepareIndex("test").setId("2").setSource("f1", "bar"));
597608
reqs.add(client().prepareIndex("test").setId("3").setSource("f1", "foo bar"));
598609
indexRandom(true, false, reqs);
610+
indexRandomForConcurrentSearch("test");
599611

600612
SearchResponse resp = client().prepareSearch("test").setQuery(simpleQueryStringQuery("foo")).get();
601613
assertHits(resp.getHits(), "3");
@@ -663,6 +675,7 @@ public void testFieldAlias() throws Exception {
663675
indexRequests.add(client().prepareIndex("test").setId("2").setSource("f3", "value", "f2", "two"));
664676
indexRequests.add(client().prepareIndex("test").setId("3").setSource("f3", "another value", "f2", "three"));
665677
indexRandom(true, false, indexRequests);
678+
indexRandomForConcurrentSearch("test");
666679

667680
SearchResponse response = client().prepareSearch("test").setQuery(simpleQueryStringQuery("value").field("f3_alias")).get();
668681

@@ -681,6 +694,7 @@ public void testFieldAliasWithWildcardField() throws Exception {
681694
indexRequests.add(client().prepareIndex("test").setId("2").setSource("f3", "value", "f2", "two"));
682695
indexRequests.add(client().prepareIndex("test").setId("3").setSource("f3", "another value", "f2", "three"));
683696
indexRandom(true, false, indexRequests);
697+
indexRandomForConcurrentSearch("test");
684698

685699
SearchResponse response = client().prepareSearch("test").setQuery(simpleQueryStringQuery("value").field("f3_*")).get();
686700

@@ -697,6 +711,7 @@ public void testFieldAliasOnDisallowedFieldType() throws Exception {
697711
List<IndexRequestBuilder> indexRequests = new ArrayList<>();
698712
indexRequests.add(client().prepareIndex("test").setId("1").setSource("f3", "text", "f2", "one"));
699713
indexRandom(true, false, indexRequests);
714+
indexRandomForConcurrentSearch("test");
700715

701716
// The wildcard field matches aliases for both a text and boolean field.
702717
// By default, the boolean field should be ignored when building the query.

0 commit comments

Comments
 (0)