You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "TanYuxin-tyx (via GitHub)" <gi...@apache.org> on 2023/03/16 04:29:32 UTC

[GitHub] [flink] TanYuxin-tyx commented on a diff in pull request #22161: [FLINK-31405] Refactor tests to git rid of timeout of CompletableFuture assertions.

TanYuxin-tyx commented on code in PR #22161:
URL: https://github.com/apache/flink/pull/22161#discussion_r1138090110


##########
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/AdaptiveSchedulerTest.java:
##########
@@ -1311,11 +1312,10 @@ public void testTriggerSavepointFailsInIllegalState() throws Exception {
                 new AdaptiveSchedulerBuilder(createJobGraph(), mainThreadExecutor)
                         .build(EXECUTOR_RESOURCE.getExecutor());
 
-        assertThat(
+        assertThatFuture(
                         scheduler.triggerSavepoint(
                                 "some directory", false, SavepointFormatType.CANONICAL))
-                .failsWithin(1, TimeUnit.MILLISECONDS)
-                .withThrowableOfType(ExecutionException.class)
+                .eventuallyFailsWith(ExecutionException.class)
                 .withCauseInstanceOf(CheckpointException.class);
     }
 

Review Comment:
   We'd better to update this test class to Junit 5.



##########
flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/FlinkCompletableFutureAssert.java:
##########
@@ -46,6 +48,9 @@
 
     private static final String SHOULD_HAVE_FAILED = "%nExpecting%n  <%s>%nto have failed.%n";
 
+    private static final String SHOULD_NOT_COMPLETED =
+            "%nExpecting%n  <%s>%nto have not completed normally or exceptionally.%n";
+

Review Comment:
   I think this is not clearly enough when users encounter the exception because of lacking the timeout time. We'd better change it to the message as follows.
   ```suggestion
   private static final String SHOULD_NOT_COMPLETED =
               "%nExpecting%n  <%s>%nto have not completed normally or exceptionally within %s ms.%n";
   ```



##########
flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/FlinkCompletableFutureAssert.java:
##########
@@ -133,4 +150,19 @@ private Exception assertEventuallyFails(AssertionInfo info, Future<?> actual) {
             return e;
         }
     }
+
+    private void assertWillNotCompleteWithin(
+            AssertionInfo info, Future<T> actual, Duration duration) {
+        Objects.instance().assertNotNull(info, actual);
+        try {
+            actual.get(duration.toMillis(), TimeUnit.MILLISECONDS);
+            throw Failures.instance()
+                    .failure(info, new BasicErrorMessageFactory(SHOULD_NOT_COMPLETED, actual));

Review Comment:
   Here we should add the argument `duration.toMillis()` accordingly. 



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org