From 34d858fbbbf0a997bff89f061c7bbbb8911ee1ea Mon Sep 17 00:00:00 2001 From: Benjamin Trent <4357155+benwtrent@users.noreply.github.com> Date: Tue, 7 Nov 2023 07:55:28 -0500 Subject: [PATCH] Fix KnnQueryTestCase Both testEuclidean and testExplain have vectors that result in equal scores. Since we no longer tie break on vector ordinal as it doesn't make sense when building the graph, the vectors returned might be slightly different. This commit fixes the flaky nature of the test. --- .../search/BaseKnnVectorQueryTestCase.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lucene/core/src/test/org/apache/lucene/search/BaseKnnVectorQueryTestCase.java b/lucene/core/src/test/org/apache/lucene/search/BaseKnnVectorQueryTestCase.java index d45902d3bb3..fb4775712a0 100644 --- a/lucene/core/src/test/org/apache/lucene/search/BaseKnnVectorQueryTestCase.java +++ b/lucene/core/src/test/org/apache/lucene/search/BaseKnnVectorQueryTestCase.java @@ -281,12 +281,19 @@ abstract class BaseKnnVectorQueryTestCase extends LuceneTestCase { DocIdSetIterator it = scorer.iterator(); assertEquals(3, it.cost()); - assertEquals(2, it.nextDoc()); - assertEquals(1 / 2f, scorer.score(), 0); - assertEquals(4, it.advance(4)); - assertEquals(1 / 6f, scorer.score(), 0); - - assertEquals(NO_MORE_DOCS, it.advance(5)); + int firstDoc = it.nextDoc(); + if (firstDoc == 1) { + assertEquals(1 / 6f, scorer.score(), 0); + assertEquals(3, it.advance(3)); + assertEquals(1 / 2f, scorer.score(), 0); + assertEquals(NO_MORE_DOCS, it.advance(4)); + } else { + assertEquals(2, firstDoc); + assertEquals(1 / 2f, scorer.score(), 0); + assertEquals(4, it.advance(4)); + assertEquals(1 / 6f, scorer.score(), 0); + assertEquals(NO_MORE_DOCS, it.advance(5)); + } expectThrows(ArrayIndexOutOfBoundsException.class, scorer::score); } } @@ -384,7 +391,7 @@ abstract class BaseKnnVectorQueryTestCase extends LuceneTestCase { assertEquals(0, matched.getDetails().length); assertEquals("within top 3 docs", matched.getDescription()); - Explanation nomatch = searcher.explain(query, 1); + Explanation nomatch = searcher.explain(query, 5); assertFalse(nomatch.isMatch()); assertEquals(0f, nomatch.getValue()); assertEquals(0, matched.getDetails().length);