Github user StephanEwen commented on a diff in the pull request:
https://github.com/apache/flink/pull/2652#discussion_r83842005
--- Diff:
flink-runtime/src/test/java/org/apache/flink/runtime/taskmanager/TaskTest.java
---
@@ -565,6 +568,128 @@ public void testOnPartitionStateUpdate() throws
Exception {
verify(inputGate,
times(1)).retriggerPartitionRequest(eq(partitionId.getPartitionId()));
}
+ /**
+ * Tests that interrupt happens via watch dog if canceller is stuck in
cancel.
+ * Task cancellation blocks the task canceller. Interrupt after cancel
via
+ * cancellation watch dog.
+ */
+ @Test
+ public void testWatchDogInterruptsTask() throws Exception {
+ Configuration config = new Configuration();
+ config.setLong(TaskOptions.CANCELLATION_INTERVAL.key(), 5);
+ config.setLong(TaskOptions.CANCELLATION_TIMEOUT.key(), 50);
+
+ Task task = createTask(InvokableBlockingInCancel.class, config);
+ task.startTaskThread();
+
+ awaitLatch.await();
+
+ task.cancelExecution();
+
+ triggerLatch.await();
+
+ // No fatal error
+ for (Object msg : taskManagerMessages) {
+ assertEquals(false, msg instanceof
TaskManagerMessages.FatalError);
+ }
+ }
+
+ /**
+ * The invoke() method holds a lock (trigger awaitLatch after
acquisition)
+ * and cancel cannot complete because it also tries to acquire the same
lock.
+ * This is resolved by the watch dog, no fatal error.
+ */
+ @Test
+ public void testInterruptableSharedLockInInvokeAndCancel() throws
Exception {
+ Configuration config = new Configuration();
+ config.setLong(TaskOptions.CANCELLATION_INTERVAL.key(), 5);
+ config.setLong(TaskOptions.CANCELLATION_TIMEOUT.key(), 50);
+
+ Task task =
createTask(InvokableInterruptableSharedLockInInvokeAndCancel.class, config);
+ task.startTaskThread();
+
+ awaitLatch.await();
+
+ task.cancelExecution();
+
+ triggerLatch.await();
+
+ // No fatal error
+ for (Object msg : taskManagerMessages) {
+ assertEquals(false, msg instanceof
TaskManagerMessages.FatalError);
--- End diff --
You can also give a message to `assertFalse` - I like assertEquals for
printing the expected value, but if the expected value is false, the former
seems more natural to me...
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---