LUCENE-10085: Fix rare failure in TestDocValuesFieldExistsQuery (#784)

In rare cases, this test could delete all documents and cause a failure.
This commit is contained in:
Quentin Pradet 2022-04-05 21:30:01 +04:00 committed by GitHub
parent a071180a80
commit 6062ba0b3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 4 deletions

View File

@ -304,13 +304,15 @@ public class TestDocValuesFieldExistsQuery extends LuceneTestCase {
Directory dir = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random(), dir);
int randomNumDocs = TestUtil.nextInt(random(), 10, 100);
int randomNumDocs = TestUtil.nextInt(random(), 11, 100);
int numMatchingDocs = 0;
for (int i = 0; i < randomNumDocs; i++) {
Document doc = new Document();
// ensure we index at least a document with long between 0 and 10
if (i == 0 || random().nextBoolean()) {
// We select most documents randomly but keep two documents:
// * #0 ensures we will delete at least one document (with long between 0 and 9)
// * #10 ensures we will keep at least one document (with long greater than 9)
if (i == 0 || i == 10 || random().nextBoolean()) {
doc.add(new LongPoint("long", i));
doc.add(new NumericDocValuesField("long", i));
doc.add(new StringField("string", "value", Store.NO));
@ -330,7 +332,7 @@ public class TestDocValuesFieldExistsQuery extends LuceneTestCase {
// Test that we can't count in O(1) when there are deleted documents
w.w.getConfig().setMergePolicy(NoMergePolicy.INSTANCE);
w.deleteDocuments(LongPoint.newRangeQuery("long", 0L, 10L));
w.deleteDocuments(LongPoint.newRangeQuery("long", 0L, 9L));
DirectoryReader reader2 = w.getReader();
final IndexSearcher searcher2 = new IndexSearcher(reader2);
final Query testQuery = new DocValuesFieldExistsQuery("long");