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.
This commit is contained in:
Armin Braun 2020-10-26 10:27:08 +01:00 committed by GitHub
parent adc5509eda
commit 17843a40ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -481,6 +481,7 @@ public class SearchableSnapshotDirectoryTests extends ESTestCase {
final ShardId shardId = new ShardId(indexSettings.getIndex(), randomIntBetween(0, 10));
final List<Releasable> 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 {