Skip to content

Commit

Permalink
Fix IndicesRequestCacheIt flaky tests (opensearch-project#16276)
Browse files Browse the repository at this point in the history
Signed-off-by: Sagar Upadhyaya <sagar.upadhyaya.121@gmail.com>
  • Loading branch information
sgup432 authored and dk2k committed Oct 21, 2024
1 parent 87d9b5a commit e905417
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;

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

indexRandomForConcurrentSearch(index);

// Force merge the index to ensure there can be no background merges during the subsequent searches that would invalidate the cache
ForceMergeResponse forceMergeResponse = client.admin().indices().prepareForceMerge(index).setFlush(true).get();
OpenSearchAssertions.assertAllSuccessful(forceMergeResponse);

assertCacheState(client, index, 0, 0);

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

0 comments on commit e905417

Please sign in to comment.