rkhachatryan commented on a change in pull request #14968: URL: https://github.com/apache/flink/pull/14968#discussion_r580141605
########## 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: I agree that the probability is very low (also such check won't be needed if we don't loop in the source and ony `await` on some latch). ---------------------------------------------------------------- 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