pnowojski commented on a change in pull request #14573:
URL: https://github.com/apache/flink/pull/14573#discussion_r553290936



##########
File path: 
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java
##########
@@ -1256,54 +1309,97 @@ public void testProcessWithUnAvailableOutput() throws 
Exception {
 
             final RunnableWithException completeFutureTask =
                     () -> {
-                        Thread.sleep(sleepTime + 1);
                         assertEquals(1, inputProcessor.currentNumProcessCalls);
                         
assertTrue(task.mailboxProcessor.isDefaultActionUnavailable());
                         
environment.getWriter(1).getAvailableFuture().complete(null);
                     };
 
+            waitingThread =
+                    new WaitingThread(
+                            executor,
+                            completeFutureTask,
+                            sleepTimeInsideMail,
+                            sleepTimeOutsideMail);
+            // Make sure WaitingThread is started after Task starts processing.
             executor.submit(
-                    () -> {
-                        executor.submit(
-                                completeFutureTask,
-                                "This task will complete the future to resume 
process input action.");
-                    },
+                    waitingThread::start,
                     "This task will submit another task to execute after 
processing input once.");
 
+            long startTs = System.currentTimeMillis();
             TaskIOMetricGroup ioMetricGroup =
                     task.getEnvironment().getMetricGroup().getIOMetricGroup();
             task.invoke();
+            long totalDuration = System.currentTimeMillis() - startTs;
+            assertThat(
+                    ioMetricGroup.getBackPressuredTimePerSecond().getCount(),
+                    Matchers.greaterThanOrEqualTo(sleepTimeOutsideMail));
             assertThat(
                     ioMetricGroup.getBackPressuredTimePerSecond().getCount(),
-                    Matchers.greaterThanOrEqualTo(sleepTime));
+                    Matchers.lessThanOrEqualTo(totalDuration - 
sleepTimeInsideMail));
             assertThat(ioMetricGroup.getIdleTimeMsPerSecond().getCount(), 
is(0L));
             assertEquals(numberOfProcessCalls, 
inputProcessor.currentNumProcessCalls);
+        } finally {
+            if (waitingThread != null) {

Review comment:
       I didn't want to introduce another layer of `try/catch`.




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

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


Reply via email to