Github user JoshRosen commented on a diff in the pull request:
https://github.com/apache/spark/pull/4135#discussion_r28023348
--- Diff:
core/src/test/scala/org/apache/spark/scheduler/TaskContextSuite.scala ---
@@ -64,6 +64,53 @@ class TaskContextSuite extends FunSuite with
BeforeAndAfter with LocalSparkConte
verify(listener, times(1)).onTaskCompletion(any())
}
+ test("calls TaskInterruptionListener when task killed") {
+ TaskContextSuite.interrupted = false
+ sc = new SparkContext("local", "test")
+ val rdd = new RDD[String](sc, List()) {
+ override def getPartitions = Array[Partition](StubPartition(0))
+ override def compute(split: Partition, context: TaskContext) = {
+ context.addTaskInterruptionListener(context =>
TaskContextSuite.interrupted = true)
+ Thread.sleep(1000)
+ Iterator("test")
+ }
+ }
+ val closureSerializer = SparkEnv.get.closureSerializer.newInstance()
+ val func = (c: TaskContext, i: Iterator[String]) => i.next()
+ val task = new ResultTask[String, String](
+ 0, sc.broadcast(closureSerializer.serialize((rdd, func)).array),
rdd.partitions(0), Seq(), 0)
+
+ task.kill(false)
+ assert(TaskContextSuite.interrupted === false)
+
+ val taskThread = new Thread("Task") {
+ override def run(): Unit = {
+ task.run(0, 0)
+ }
+ }
+ taskThread.start()
+ Thread.sleep(500)
--- End diff --
If possible, we should avoid adding any new Thread.sleep() calls in our
tests, since they slow things down and have been a major source of flakiness in
the past. How about adding a CountdownLatch to the TaskContexSuite companion
object and using that to block the main thread until the body of the task has
started executing and the interruption listener has been registered?
---
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.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]