From c435702792263ee5dca20534a236ee0a3b828ef8 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Tue, 10 Oct 2023 10:38:39 +0100 Subject: [PATCH] MatchingDirectoryReader should not use a threaded searcher (#100527) MatchingDirectoryReader is a test reader wrapper that filters out documents matching a particular query. For each leaf, we create an IndexSearcher, execute the query against it and then use that as a filter for the leaf. This searcher is created using LuceneTestCase.newSearcher() and as such may be multi- threaded, which triggers extra index checks. For tests that are expecting certain methods to be called against internal readers a given number of times, these extra checks can add additional calls which then lead to a failure of test assumptions. Because this IndexSearcher is only executed against a single leaf it will only ever use a single thread, and so we can explicitly disable threading here. Fixes #100487 Fixes #99916 --- .../java/org/elasticsearch/index/engine/EngineTestCase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java index 03e61d5cb3037..811967c45c999 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/index/engine/EngineTestCase.java @@ -1513,7 +1513,7 @@ public MatchingDirectoryReader(DirectoryReader in, Query query) throws IOExcepti @Override public LeafReader wrap(LeafReader leaf) { try { - final IndexSearcher searcher = newSearcher(leaf, false); + final IndexSearcher searcher = newSearcher(leaf, false, true, false); searcher.setQueryCache(null); final Weight weight = searcher.createWeight(query, ScoreMode.COMPLETE_NO_SCORES, 1.0f); final Scorer scorer = weight.scorer(leaf.getContext());