New attempt at addressing testHasUncommittedChanges() failures.

This commit is contained in:
Adrien Grand 2023-11-14 23:11:06 +01:00
parent b45c21f9db
commit a13a4224d8
1 changed files with 5 additions and 15 deletions

View File

@ -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();