Github user zsxwing commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16872#discussion_r100399822
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/DataFrameRangeSuite.scala ---
    @@ -127,4 +133,28 @@ class DataFrameRangeSuite extends QueryTest with 
SharedSQLContext {
           }
         }
       }
    +
    +  test("Cancelling stage in a query with Range.") {
    +    val listener = new SparkListener {
    +      override def onTaskStart(taskStart: SparkListenerTaskStart): Unit = {
    +        Thread.sleep(100)
    --- End diff --
    
    Sorry that I didn't see `sparkContext.cancelStage(taskStart.stageId)`. How 
about this:
    
    ```Scala
    class DataFrameRangeSuite {
      ...
      test("Cancelling stage in a query with Range.") {
        DataFrameRangeSuite.isTaskStarted = false
        val listener = new SparkListener {
          override def onTaskStart(taskStart: SparkListenerTaskStart): Unit = {
            eventually(timeout(20.seconds)) {
              assert(DataFrameRangeSuite.isTaskStarted)
            }
            sparkContext.cancelStage(taskStart.stageId)
          }
        }
        sparkContext.addSparkListener(listener)
        for (codegen <- Seq(true, false)) {
          withSQLConf(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key -> 
codegen.toString()) {
            import testImplicits._
            val ex = intercept[SparkException] {
              spark.range(100000L).map { i =>
                DataFrameRangeSuite.isTaskStarted = true
                i
              }.crossJoin(spark.range(100000L))
                .toDF("a", "b").agg(sum("a"), sum("b")).collect()
            }
            ex.getCause() match {
              case null =>
                assert(ex.getMessage().contains("cancelled"))
              case cause: SparkException =>
                assert(cause.getMessage().contains("cancelled"))
              case cause: Throwable =>
                fail("Expected the casue to be SparkException, got " + 
cause.toString() + " instead.")
            }
          }
          eventually(timeout(20.seconds)) {
            
assert(sparkContext.statusTracker.getExecutorInfos.map(_.numRunningTasks()).sum 
== 0)
          }
        }
      }
    }
    
    object DataFrameRangeSuite {
      @volatile var isTaskStarted = false
    }
    ```


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to