You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ja...@apache.org on 2026/10/09 14:21:35 UTC

(lucene) branch branch_10x updated: Tests: Use AtomicInteger to prevent races in BaseKnnVectorQueryTestCase (#16786)

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

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


The following commit(s) were added to refs/heads/branch_10x by this push:
     new 081c135f489 Tests: Use AtomicInteger to prevent races in BaseKnnVectorQueryTestCase (#16786)
081c135f489 is described below

commit 081c135f489993c20450f3621d6041f2554f2008
Author: Alexander Reelsen <al...@spinscale.de>
AuthorDate: Fri Oct 9 16:18:14 2026 +0200

    Tests: Use AtomicInteger to prevent races in BaseKnnVectorQueryTestCase (#16786)
---
 .../org/apache/lucene/search/BaseKnnVectorQueryTestCase.java | 12 +++++-------
 1 file changed, 5 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 611dd148a6f..3a9589f75e3 100644
--- a/lucene/core/src/test/org/apache/lucene/search/BaseKnnVectorQueryTestCase.java
+++ b/lucene/core/src/test/org/apache/lucene/search/BaseKnnVectorQueryTestCase.java
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.util.HashSet;
 import java.util.Random;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.lucene.codecs.KnnVectorsFormat;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
@@ -1215,20 +1216,17 @@ abstract class BaseKnnVectorQueryTestCase extends LuceneTestCase {
     }
   }
 
+  /** Must be thread-safe: per-segment kNN searches may call it concurrently. */
   private static class CountingQueryTimeout implements QueryTimeout {
-    private int remaining;
+    private final AtomicInteger remaining;
 
     public CountingQueryTimeout(int count) {
-      remaining = count;
+      remaining = new AtomicInteger(count);
     }
 
     @Override
     public boolean shouldExit() {
-      if (remaining > 0) {
-        remaining--;
-        return false;
-      }
-      return true;
+      return remaining.getAndUpdate(r -> r > 0 ? r - 1 : 0) == 0;
     }
   }