Skip to content

Commit 20536ee

Browse files
authored
Fix IndicesRequestCacheIt flaky tests (#16276)
Signed-off-by: Sagar Upadhyaya <sagar.upadhyaya.121@gmail.com>
1 parent 53c9ddf commit 20536ee

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

server/src/internalClusterTest/java/org/opensearch/indices/IndicesRequestCacheIT.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import java.util.Arrays;
8585
import java.util.Collection;
8686
import java.util.List;
87+
import java.util.concurrent.TimeUnit;
8788

8889
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
8990
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
@@ -586,6 +587,7 @@ public void testCacheWithFilteredAlias() throws InterruptedException {
586587
.put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true)
587588
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
588589
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
590+
.put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), TimeValue.timeValueMillis(-1))
589591
.build();
590592
String index = "index";
591593
assertAcked(
@@ -599,13 +601,14 @@ public void testCacheWithFilteredAlias() throws InterruptedException {
599601
);
600602
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
601603
client.prepareIndex(index).setId("1").setRouting("1").setSource("created_at", DateTimeFormatter.ISO_LOCAL_DATE.format(now)).get();
602-
// Force merge the index to ensure there can be no background merges during the subsequent searches that would invalidate the cache
603-
ForceMergeResponse forceMergeResponse = client.admin().indices().prepareForceMerge(index).setFlush(true).get();
604-
OpenSearchAssertions.assertAllSuccessful(forceMergeResponse);
605604
refreshAndWaitForReplication();
606605

607606
indexRandomForConcurrentSearch(index);
608607

608+
// Force merge the index to ensure there can be no background merges during the subsequent searches that would invalidate the cache
609+
ForceMergeResponse forceMergeResponse = client.admin().indices().prepareForceMerge(index).setFlush(true).get();
610+
OpenSearchAssertions.assertAllSuccessful(forceMergeResponse);
611+
609612
assertCacheState(client, index, 0, 0);
610613

611614
SearchResponse r1 = client.prepareSearch(index)
@@ -823,7 +826,7 @@ public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float bo
823826
SearchResponse resp = client.prepareSearch(index)
824827
.setRequestCache(true)
825828
.setQuery(timeoutQueryBuilder)
826-
.setTimeout(TimeValue.ZERO)
829+
.setTimeout(new TimeValue(5, TimeUnit.MILLISECONDS))
827830
.get();
828831
assertTrue(resp.isTimedOut());
829832
RequestCacheStats requestCacheStats = getRequestCacheStats(client, index);

0 commit comments

Comments
 (0)