sejal-gupta-ksolves commented on code in PR #18396:
URL: https://github.com/apache/iceberg/pull/18396#discussion_r4216093026


##########
core/src/test/java/org/apache/iceberg/rest/TestScanTaskIterable.java:
##########
@@ -602,4 +608,50 @@ public void closeWithFullQueueDoesNotHangWorkers() throws 
Exception {
         .as("Executor should terminate - workers should have exited 
gracefully")
         .isTrue();
   }
+
+  @Test
+  public void backgroundWorkerLeakOnEarlyClose() throws Exception {
+    /* * Generate tasks exceeding the default queue capacity (1000) to ensure
+     * that background PlanTaskWorker threads fill the buffer and block.
+     */
+    int totalTasks = 1050;
+    List<FileScanTask> mockTasks =
+        IntStream.range(0, totalTasks)
+            .mapToObj(i -> Mockito.mock(FileScanTask.class))
+            .collect(Collectors.toList());
+
+    ThreadPoolExecutor planningExecutor = (ThreadPoolExecutor) 
Executors.newFixedThreadPool(4);
+
+    ScanTaskIterable scanTaskIterable =
+        new ScanTaskIterable(
+            Collections.emptyList(),
+            mockTasks,
+            Mockito.mock(RESTClient.class),
+            null,
+            null,
+            Collections.emptyMap(),
+            planningExecutor,
+            null);
+
+    CloseableIterable<FileScanTask> wrappedIterable =
+        CloseableIterable.whenComplete(scanTaskIterable, () -> {});
+
+    CloseableIterator<FileScanTask> iterator = wrappedIterable.iterator();
+    if (iterator.hasNext()) {
+      iterator.next();
+    }
+
+    wrappedIterable.close();
+
+    Awaitility.await()
+        .atMost(Duration.ofSeconds(5))
+        .untilAsserted(() -> 
assertThat(planningExecutor.getActiveCount()).isEqualTo(0));

Review Comment:
   Duration.ofSeconds(5) is just the maximum timeout cap for Awaitility, not a 
fixed sleep delay. Awaitility polls the condition continuously and completes as 
soon as getActiveCount() reaches 0.   The timeout acts as a guardrail so the 
test doesn't hang indefinitely if background threads take a few extra 
milliseconds under heavy CI load.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to