From 791913385881f45985e2dbab6b72cd02a5d56fb4 Mon Sep 17 00:00:00 2001 From: Chris Hegarty <62058229+ChrisHegarty@users.noreply.github.com> Date: Thu, 30 Nov 2023 08:39:26 +0000 Subject: [PATCH] Fix intermittently failing TestSortedSetFieldSource (#12850) This commit fixes the intermittently failing TestSortedSetFieldSource. The test assertions depend on doc order which may be affected by merging. The fix is to trivially avoid merging for the very small index, with just two docs. --- .../queries/function/TestSortedSetFieldSource.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/TestSortedSetFieldSource.java b/lucene/queries/src/test/org/apache/lucene/queries/function/TestSortedSetFieldSource.java index 27bd2192a9d..3245ec8d40f 100644 --- a/lucene/queries/src/test/org/apache/lucene/queries/function/TestSortedSetFieldSource.java +++ b/lucene/queries/src/test/org/apache/lucene/queries/function/TestSortedSetFieldSource.java @@ -22,7 +22,9 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.SortedSetDocValuesField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.LeafReader; +import org.apache.lucene.index.NoMergePolicy; import org.apache.lucene.queries.function.valuesource.SortedSetFieldSource; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.IndexSearcher; @@ -31,13 +33,17 @@ import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortedSetSortField; import org.apache.lucene.store.Directory; +import org.apache.lucene.tests.analysis.MockAnalyzer; import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.lucene.util.BytesRef; public class TestSortedSetFieldSource extends LuceneTestCase { public void testSimple() throws Exception { Directory dir = newDirectory(); - IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(null)); + IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random())); + conf.setMaxBufferedDocs(2); // generate few segments + conf.setMergePolicy(NoMergePolicy.INSTANCE); // prevent merges for this test + IndexWriter writer = new IndexWriter(dir, conf); Document doc = new Document(); doc.add(new SortedSetDocValuesField("value", new BytesRef("baz"))); doc.add(newStringField("id", "2", Field.Store.YES)); @@ -47,7 +53,6 @@ public class TestSortedSetFieldSource extends LuceneTestCase { doc.add(new SortedSetDocValuesField("value", new BytesRef("bar"))); doc.add(newStringField("id", "1", Field.Store.YES)); writer.addDocument(doc); - writer.forceMerge(1); writer.close(); DirectoryReader ir = DirectoryReader.open(dir);