Skip to content

Apache Lucene open-source search software

New attempt at addressing testHasUncommittedChanges() failures.

Adrien Granda13a4224d829
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
index 015cad6b523..5c0303d9f9e 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
@@ -2376,9 +2376,9 @@ public class TestIndexWriter extends LuceneTestCase {
new IndexWriter(
dir,
newIndexWriterConfig(new MockAnalyzer(random()))
- // Use a serial merge scheduler to avoid race conditions when checking for
- // hasPendingMerges()
- .setMergeScheduler(new SerialMergeScheduler()));
+ // Disable merging to simplify this test, otherwise a commit might trigger
+ // uncommitted merges.
+ .setMergePolicy(NoMergePolicy.INSTANCE));
assertTrue(
writer.hasUncommittedChanges()); // this will be true because a commit will create an empty
// index
@@ -2401,22 +2401,12 @@ public class TestIndexWriter extends LuceneTestCase {
writer.addDocument(doc);
assertTrue(writer.hasUncommittedChanges());
- // Must commit and wait for merges as long as the commit triggers merges to be certain that
- // hasUncommittedChanges returns false
- do {
- writer.waitForMerges();
- writer.commit();
- } while (writer.hasPendingMerges());
+ writer.commit();
assertFalse(writer.hasUncommittedChanges());
writer.deleteDocuments(new Term("id", "xyz"));
assertTrue(writer.hasUncommittedChanges());
- // Must commit and wait for merges as long as the commit triggers merges to be certain that
- // hasUncommittedChanges returns false
- do {
- writer.waitForMerges();
- writer.commit();
- } while (writer.hasPendingMerges());
+ writer.commit();
assertFalse(writer.hasUncommittedChanges());
writer.close();