snuyanzin commented on code in PR #22127:
URL: https://github.com/apache/flink/pull/22127#discussion_r1129193253


##########
flink-table/flink-sql-gateway/src/test/java/org/apache/flink/table/gateway/service/operation/OperationManagerTest.java:
##########
@@ -129,29 +135,54 @@ public void testCancelOperation() throws Exception {
     }
 
     @Test
-    public void testCancelOperationByForce() throws Exception {
-        AtomicReference<Throwable> exception = new AtomicReference<>(null);
+    public void testCancelUninterruptedOperation() throws Exception {
+        AtomicReference<Boolean> isRunning = new AtomicReference<>(false);
         OperationHandle operationHandle =
                 operationManager.submitOperation(
                         () -> {
-                            try {
-                                // mock cpu busy task that doesn't interrupt 
system call
-                                while (true) {}
-                            } catch (Throwable t) {
-                                exception.set(t);
-                                throw t;
+                            // mock cpu busy task that doesn't interrupt 
system call
+                            while (true) {
+                                isRunning.compareAndSet(false, true);
                             }
                         });
-
-        threadFactory.newThread(() -> 
operationManager.cancelOperation(operationHandle)).start();
-        operationManager.awaitOperationTermination(operationHandle);
+        CommonTestUtils.waitUtil(
+                isRunning::get, Duration.ofSeconds(10), "Failed to start up 
the task.");
+        assertThatThrownBy(() -> 
operationManager.cancelOperation(operationHandle))
+                .satisfies(
+                        FlinkAssertions.anyCauseMatches(
+                                SqlCancelException.class,
+                                String.format(
+                                        "Operation '%s' did not react to 
\"Future.cancel(true)\" and "
+                                                + "is stuck for %s seconds in 
method.\n",
+                                        operationHandle, 5)));
 
         
assertThat(operationManager.getOperationInfo(operationHandle).getStatus())
                 .isEqualTo(OperationStatus.CANCELED);
+    }
+
+    @Test
+    public void testCloseUninterruptedOperation() throws Exception {

Review Comment:
   nit: modifier could be package private
   ```suggestion
       void testCloseUninterruptedOperation() throws Exception {
   ```



-- 
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]

Reply via email to