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



##########
File path: 
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/SourceStreamTaskTest.java
##########
@@ -856,4 +887,41 @@ private void output(String record) {
             output.collect(new StreamRecord<>(record));
         }
     }
+
+    /**
+     * This source sleeps a little bit before processing cancellation and 
records whether it was
+     * interrupted by the {@link SourceStreamTask} or not.
+     */
+    private static class WasInterruptedTestingSource implements 
SourceFunction<String> {
+        private static final int MAX_POST_CANCEL_ITERATIONS = 100;
+        private static final long serialVersionUID = 1L;
+        private volatile boolean running;
+
+        public static boolean wasInterrupted;
+
+        @Override
+        public void run(SourceContext<String> ctx) throws Exception {
+            wasInterrupted = false;
+            try {
+                int postCancelIterations = 0;
+                while (running || postCancelIterations < 
MAX_POST_CANCEL_ITERATIONS) {
+                    Thread.sleep(1);
+                    if (!running) {
+                        postCancelIterations++;
+                    }
+                }
+            } catch (InterruptedException e) {
+                wasInterrupted = true;

Review comment:
       The tested window if interruption has happened or not is 100ms (10^-1 
seconds). After the sleep we have only a couple of instructions to perform 
(exiting the loop). So adding `interrupted` such check would extend this window 
by  something between 1 micro second (10^-6 s) (assuming we would need to check 
volatiles) and 1 nano second (10^-9 s). 
   
   That's a difference of 5 to 8 orders of magnitudes, I don't think extra 
complexity/more code is worth for checking that.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to