You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ju...@apache.org on 2022/04/05 17:48:21 UTC

[lucene] branch branch_9x updated: LUCENE-10085: Fix rare failure in TestDocValuesFieldExistsQuery (#784)

This is an automated email from the ASF dual-hosted git repository.

julietibs pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new be1c4850441 LUCENE-10085: Fix rare failure in TestDocValuesFieldExistsQuery (#784)
be1c4850441 is described below

commit be1c4850441f7cff07f5ce20c9ed4ad203cabb21
Author: Quentin Pradet <qu...@elastic.co>
AuthorDate: Tue Apr 5 21:30:01 2022 +0400

    LUCENE-10085: Fix rare failure in TestDocValuesFieldExistsQuery (#784)
    
    In rare cases, this test could delete all documents and cause a failure.
---
 .../apache/lucene/search/TestDocValuesFieldExistsQuery.java    | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lucene/core/src/test/org/apache/lucene/search/TestDocValuesFieldExistsQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestDocValuesFieldExistsQuery.java
index 32f163ba99e..3541dc7a213 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestDocValuesFieldExistsQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestDocValuesFieldExistsQuery.java
@@ -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");