diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsRestTestCase.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsRestTestCase.java index 0800edf72b1e4..c7dd28a1e6bdb 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsRestTestCase.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsRestTestCase.java @@ -203,8 +203,10 @@ public void testClearCache() throws Exception { searchResults = search(restoredIndexName, QueryBuilders.matchAllQuery(), Boolean.TRUE); assertThat(extractValue(searchResults, "hits.total.value"), equalTo(numDocs)); - final long bytesInCacheAfterSearch = sumCachedBytesWritten.apply(searchableSnapshotStats(restoredIndexName)); - assertThat(bytesInCacheAfterSearch, greaterThan(bytesInCacheBeforeClear)); + assertBusy(() -> { + final long bytesInCacheAfterSearch = sumCachedBytesWritten.apply(searchableSnapshotStats(restoredIndexName)); + assertThat(bytesInCacheAfterSearch, greaterThan(bytesInCacheBeforeClear)); + }); }); } @@ -419,6 +421,6 @@ protected static T extractValue(Map map, String path) { */ @FunctionalInterface interface SearchableSnapshotsTestCaseBody { - void runTest(String indexName, int numDocs) throws IOException; + void runTest(String indexName, int numDocs) throws Exception; } }