From 04a494ce5f7512882e1aebed9265cd81959472d2 Mon Sep 17 00:00:00 2001 From: SEPURI-SAI-KRISHNA Date: Tue, 15 Sep 2026 21:02:46 +0530 Subject: [PATCH] [FLINK-40675][sql-gateway] Fix unstable SqlGatewayServiceITCase#testReleaseLockWhenFailedToSubmitOperation Generated-by: Claude Code (Opus 5) --- .../service/SqlGatewayServiceITCase.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/SqlGatewayServiceITCase.java b/flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/SqlGatewayServiceITCase.java index d64ed8f35f8c47..a5c434d1892088 100644 --- a/flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/SqlGatewayServiceITCase.java +++ b/flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/SqlGatewayServiceITCase.java @@ -68,6 +68,7 @@ import org.apache.flink.test.util.TestUtils; import org.apache.flink.testutils.executor.TestExecutorExtension; import org.apache.flink.util.CollectionUtil; +import org.apache.flink.util.ExceptionUtils; import org.apache.flink.util.UserClassLoaderJarTestUtils; import org.apache.flink.util.concurrent.ExecutorThreadFactory; import org.apache.flink.util.function.RunnableWithException; @@ -957,14 +958,29 @@ void testReleaseLockWhenFailedToSubmitOperation() throws Exception { latch.countDown(); // Wait the first operation finishes awaitOperationTermination(service, sessions.get(0), operations.get(0)); - // Service is able to submit operation + // Service is able to submit operation. The first operation turns terminal before its + // thread is back in the pool, so retry until a thread is free. CountDownLatch success = new CountDownLatch(1); - service.submitOperation( - sessionHandle, + CommonTestUtils.waitUtil( () -> { - success.countDown(); - return getDefaultResultSet(); - }); + try { + service.submitOperation( + sessionHandle, + () -> { + success.countDown(); + return getDefaultResultSet(); + }); + return true; + } catch (SqlGatewayException e) { + if (ExceptionUtils.findThrowable(e, RejectedExecutionException.class) + .isPresent()) { + return false; + } + throw e; + } + }, + Duration.ofSeconds(10), + "The pool never freed a thread to accept the operation."); CommonTestUtils.waitUtil( () -> success.getCount() == 0, Duration.ofSeconds(10), "Should come to end."); }