You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2024/09/16 12:50:56 UTC

(lucene) branch main updated: Fix Flaky Test In TestBlockJoinBulkScorer (#13785)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new e7a63820898 Fix Flaky Test In TestBlockJoinBulkScorer (#13785)
e7a63820898 is described below

commit e7a6382089880366b5ab8027325ef6f3852e3885
Author: Mike Pellegrini <mi...@elastic.co>
AuthorDate: Mon Sep 16 08:50:51 2024 -0400

    Fix Flaky Test In TestBlockJoinBulkScorer (#13785)
---
 .../search/join/TestBlockJoinBulkScorer.java       | 49 +++++++++++++++++++---
 1 file changed, 43 insertions(+), 6 deletions(-)

diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinBulkScorer.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinBulkScorer.java
index fe5e7e37517..b9580331347 100644
--- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinBulkScorer.java
+++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinBulkScorer.java
@@ -27,6 +27,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
@@ -260,6 +261,15 @@ public class TestBlockJoinBulkScorer extends LuceneTestCase {
       Float minScore,
       Map<Integer, Float> expectedScores)
       throws IOException {
+    assertScores(bulkScorer, scoreMode, minScore, List.of(expectedScores));
+  }
+
+  private static void assertScores(
+      BulkScorer bulkScorer,
+      org.apache.lucene.search.ScoreMode scoreMode,
+      Float minScore,
+      List<Map<Integer, Float>> expectedScoresList)
+      throws IOException {
     Map<Integer, Float> actualScores = new HashMap<>();
     bulkScorer.score(
         new LeafCollector() {
@@ -283,7 +293,26 @@ public class TestBlockJoinBulkScorer extends LuceneTestCase {
         null,
         0,
         NO_MORE_DOCS);
-    assertEquals(expectedScores, actualScores);
+
+    if (expectedScoresList.size() == 1) {
+      assertEquals(expectedScoresList.getFirst(), actualScores);
+    } else {
+      assertEqualsToOneOf(expectedScoresList, actualScores);
+    }
+  }
+
+  private static void assertEqualsToOneOf(List<?> expectedList, Object actual) {
+    boolean foundMatch = false;
+    for (Object expected : expectedList) {
+      if (Objects.equals(expected, actual)) {
+        foundMatch = true;
+        break;
+      }
+    }
+
+    if (!foundMatch) {
+      throw new AssertionError("expected one of: " + expectedList + " but was: " + actual);
+    }
   }
 
   public void testScoreRandomIndices() throws IOException {
@@ -370,10 +399,18 @@ public class TestBlockJoinBulkScorer extends LuceneTestCase {
         }
 
         {
-          // Doc 16 is returned because MaxScoreBulkScorer scores assuming A will match in doc 13,
-          // leading to a potential max score of 6. By the time it determines that A doesn't match,
-          // scoring is complete and thus there is no advantage to not collecting the doc.
-          Map<Integer, Float> expectedScores =
+          // This test case has two potential results.
+          // If all docs are scored in the same batch, then doc 16 is collected because
+          // MaxScoreBulkScorer scores assuming A will match in doc 13, leading to a potential max
+          // score of 6.
+          // If the scoring is split across two or more batches, then doc 16 is not collected
+          // because MaxScoreBulkScorer does not assume A will match in doc 13, leading to a
+          // potential max score of 5.
+          Map<Integer, Float> expectedScores1 =
+              Map.of(
+                  2, 6.0f,
+                  10, 10.0f);
+          Map<Integer, Float> expectedScores2 =
               Map.of(
                   2, 6.0f,
                   10, 10.0f,
@@ -381,7 +418,7 @@ public class TestBlockJoinBulkScorer extends LuceneTestCase {
 
           ScorerSupplier ss = weight.scorerSupplier(searcher.getIndexReader().leaves().get(0));
           ss.setTopLevelScoringClause();
-          assertScores(ss.bulkScorer(), scoreMode, 6.0f, expectedScores);
+          assertScores(ss.bulkScorer(), scoreMode, 6.0f, List.of(expectedScores1, expectedScores2));
         }
 
         {