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



##########
File path: 
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/StreamTaskTest.java
##########
@@ -1256,49 +1307,82 @@ 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);
                     };
 
+            // 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.");
-                    },
+                    () ->
+                            new WaitingThread(
+                                            executor,
+                                            completeFutureTask,
+                                            sleepTimeInsideMail,
+                                            sleepTimeOutsideMail)
+                                    .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(sleepTime));
+                    Matchers.greaterThanOrEqualTo(sleepTimeOutsideMail));
+            assertThat(
+                    ioMetricGroup.getBackPressuredTimePerSecond().getCount(),
+                    Matchers.lessThanOrEqualTo(totalDuration - 
sleepTimeInsideMail));
             assertThat(ioMetricGroup.getIdleTimeMsPerSecond().getCount(), 
is(0L));
             assertEquals(numberOfProcessCalls, 
inputProcessor.currentNumProcessCalls);
         }
     }
 
     @Test
     public void testProcessWithUnAvailableInput() throws Exception {
-        final long unAvailableTime = 42;
+        final long sleepTimeOutsideMail = 42;
+        final long sleepTimeInsideMail = 44;
         try (final MockEnvironment environment = setupEnvironment(new 
boolean[] {true, true})) {
             final UnAvailableTestInputProcessor inputProcessor =
-                    new UnAvailableTestInputProcessor(unAvailableTime);
+                    new UnAvailableTestInputProcessor();
             final StreamTask task =
                     new MockStreamTaskBuilder(environment)
                             .setStreamInputProcessor(inputProcessor)
                             .build();
 
+            final MailboxExecutor executor = 
task.mailboxProcessor.getMainMailboxExecutor();
+            final RunnableWithException completeFutureTask =
+                    () -> {
+                        inputProcessor
+                                .availabilityProvider
+                                .getUnavailableToResetAvailable()
+                                .complete(null);
+                    };
+
+            // Make sure WaitingThread is started after Task starts processing.
+            executor.submit(
+                    () ->
+                            new WaitingThread(

Review comment:
       Yes. We need to sleep outside mailbox action for the time being 
accounted as idle. (That's the point of this bug fix)




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