From c85a363b600145d8b8ccf7c361dd334b5bb5738c Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 11 May 2020 15:30:08 -0400 Subject: [PATCH] Fix nested agg test I accidentally allowed the test framework to double-wrap a reader that we rely on being only singly wrapped. Lame. closes #56529 --- .../search/aggregations/AggregatorTestCase.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java b/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java index 8e1e43b66ce..79587d9828b 100644 --- a/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java @@ -555,8 +555,14 @@ public abstract class AggregatorTestCase extends ESTestCase { buildIndex.accept(indexWriter); indexWriter.close(); - try (IndexReader indexReader = wrapDirectoryReader(DirectoryReader.open(directory))) { - IndexSearcher indexSearcher = newSearcher(indexReader, true, true); + try (DirectoryReader unwrapped = DirectoryReader.open(directory); + IndexReader indexReader = wrapDirectoryReader(unwrapped)) { + /* + * Only allow the randomized testing to wrap the reader if + * the test didn't explicitly wrap the reader. + */ + boolean maybeWrap = unwrapped == indexReader; + IndexSearcher indexSearcher = newSearcher(indexReader, maybeWrap, true); V agg = searchAndReduce(indexSearcher, query, aggregationBuilder, fieldTypes); verify.accept(agg);