diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java index e2646910060..7c10d88b758 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java @@ -1387,7 +1387,7 @@ public abstract class LuceneTestCase extends Assert { r = SlowCompositeReaderWrapper.wrap(r); break; case 1: - // will create no FC insanity as Parallel*Reader has own cache key: + // will create no FC insanity in atomic case, as ParallelAtomicReader has own cache key: r = (r instanceof AtomicReader) ? new ParallelAtomicReader((AtomicReader) r) : new ParallelCompositeReader((CompositeReader) r); @@ -1419,6 +1419,9 @@ public abstract class LuceneTestCase extends Assert { } if (wasOriginallyAtomic) { r = SlowCompositeReaderWrapper.wrap(r); + } else if ((r instanceof CompositeReader) && !(r instanceof FCInvisibleMultiReader)) { + // prevent cache insanity caused by e.g. ParallelCompositeReader, to fix we wrap one more time: + r = new FCInvisibleMultiReader(r); } if (VERBOSE) { System.out.println("maybeWrapReader wrapped: " +r);