From daa56d30f0dc5370e60adc2dafd9947c65c75d4f Mon Sep 17 00:00:00 2001 From: Michael Sokolov Date: Fri, 19 Aug 2022 16:18:24 -0400 Subject: [PATCH] Fix TestHnswGraph rare failure --- .../test/org/apache/lucene/util/hnsw/TestHnswGraph.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lucene/core/src/test/org/apache/lucene/util/hnsw/TestHnswGraph.java b/lucene/core/src/test/org/apache/lucene/util/hnsw/TestHnswGraph.java index a3da10590e0..1816de726e4 100644 --- a/lucene/core/src/test/org/apache/lucene/util/hnsw/TestHnswGraph.java +++ b/lucene/core/src/test/org/apache/lucene/util/hnsw/TestHnswGraph.java @@ -206,7 +206,7 @@ public class TestHnswGraph extends LuceneTestCase { IndexReader reader2 = DirectoryReader.open(dir2)) { IndexSearcher searcher = new IndexSearcher(reader); IndexSearcher searcher2 = new IndexSearcher(reader2); - + OUTER: for (int i = 0; i < 10; i++) { // ask to explore a lot of candidates to ensure the same returned hits, // as graphs of 2 indices are organized differently @@ -217,7 +217,14 @@ public class TestHnswGraph extends LuceneTestCase { List docs2 = new ArrayList<>(); TopDocs topDocs = searcher.search(query, 5); + float lastScore = -1; for (ScoreDoc scoreDoc : topDocs.scoreDocs) { + if (scoreDoc.score == lastScore) { + // if we have repeated score this test is invalid + continue OUTER; + } else { + lastScore = scoreDoc.score; + } Document doc = reader.document(scoreDoc.doc, Set.of("id")); ids1.add(doc.get("id")); docs1.add(scoreDoc.doc);