From 17843a40ef10aa8b1a41eb71a224dcc9d4cb5352 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Mon, 26 Oct 2020 10:27:08 +0100 Subject: [PATCH] Fix SearchableSnapshotDirectoryTests.testClearCache (#64100) (#64132) There is a small chance that the file deletion will run on the searchable snapshot thread pool and not on the test thread now that the cache is non-blocking in which case we fail the assertion unless we wait for that thread. --- .../index/store/SearchableSnapshotDirectoryTests.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/index/store/SearchableSnapshotDirectoryTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/index/store/SearchableSnapshotDirectoryTests.java index 05afbf2917d..f99af1da69c 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/index/store/SearchableSnapshotDirectoryTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/index/store/SearchableSnapshotDirectoryTests.java @@ -481,6 +481,7 @@ public class SearchableSnapshotDirectoryTests extends ESTestCase { final ShardId shardId = new ShardId(indexSettings.getIndex(), randomIntBetween(0, 10)); final List releasables = new ArrayList<>(); + final ThreadPool threadPool = new TestThreadPool(getTestName(), SearchableSnapshots.executorBuilders()); try (Directory directory = newDirectory()) { final IndexWriterConfig indexWriterConfig = newIndexWriterConfig(); try (IndexWriter writer = new IndexWriter(directory, indexWriterConfig)) { @@ -507,9 +508,6 @@ public class SearchableSnapshotDirectoryTests extends ESTestCase { writer.commit(); } - final ThreadPool threadPool = new TestThreadPool(getTestName(), SearchableSnapshots.executorBuilders()); - releasables.add(() -> terminate(threadPool)); - final Store store = new Store(shardId, indexSettings, directory, new DummyShardLock(shardId)); store.incRef(); releasables.add(store::decRef); @@ -628,6 +626,8 @@ public class SearchableSnapshotDirectoryTests extends ESTestCase { } finally { Releasables.close(releasables); } + } finally { + terminate(threadPool); } } @@ -740,7 +740,7 @@ public class SearchableSnapshotDirectoryTests extends ESTestCase { assertListOfFiles(cacheDir, allOf(greaterThan(0), lessThanOrEqualTo(nbRandomFiles)), greaterThan(0L)); if (randomBoolean()) { directory.clearCache(); - assertListOfFiles(cacheDir, equalTo(0), equalTo(0L)); + assertBusy(() -> assertListOfFiles(cacheDir, equalTo(0), equalTo(0L))); } } } finally {