Skip to content

Commit 2093185

Browse files
authored
SOLR-18174 Fix test race condition failure in AsyncTrackerSemaphoreLeakTest (#4331)
1 parent 730398a commit 2093185

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

solr/core/src/test/org/apache/solr/handler/component/AsyncTrackerSemaphoreLeakTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,16 @@ public void testSemaphoreLeakOnLBRetry() throws Exception {
204204
+ " fires synchronously on the IO thread before onComplete can release().");
205205
}
206206

207-
int permitsAfterFailures = testClient.asyncTrackerAvailablePermits();
207+
// Poll briefly: apiFutures complete on the executor thread, but completeListener fires on
208+
// Jetty's IO thread after response listeners, so allOf().get() can race ahead of release().
209+
int permitsAfterFailures;
210+
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(5);
211+
do {
212+
permitsAfterFailures = testClient.asyncTrackerAvailablePermits();
213+
if (permitsAfterFailures == MAX_PERMITS) break;
214+
//noinspection BusyWait
215+
Thread.sleep(10);
216+
} while (System.nanoTime() < deadline);
208217
log.info("Permits after retries: {}/{}", permitsAfterFailures, MAX_PERMITS);
209218
assertEquals(
210219
"All permits should be restored after retries complete",

0 commit comments

Comments
 (0)