Skip to content

Commit

Permalink
[SPARK-26501][CORE][TEST] Fix unexpected overriden of exitFn in Spark…
Browse files Browse the repository at this point in the history
…SubmitSuite

## What changes were proposed in this pull request?

The overriden of SparkSubmit's exitFn at some previous tests in SparkSubmitSuite may cause the following tests pass even they failed when they were run separately. This PR is to fix this problem.

## How was this patch tested?

unittest

Closes apache#23404 from liupc/Fix-SparkSubmitSuite-exitFn.

Authored-by: Liupengcheng <liupengcheng@xiaomi.com>
Signed-off-by: Sean Owen <sean.owen@databricks.com>
(cherry picked from commit 88b074f)
Signed-off-by: Sean Owen <sean.owen@databricks.com>
  • Loading branch information
Liupengcheng authored and kai-chi committed Aug 1, 2019
1 parent fbb8ea3 commit cfaf233
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions core/src/test/scala/org/apache/spark/deploy/SparkSubmitSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,31 @@ trait TestPrematureExit {
mainObject.printStream = printStream

@volatile var exitedCleanly = false
val original = mainObject.exitFn
mainObject.exitFn = (_) => exitedCleanly = true

@volatile var exception: Exception = null
val thread = new Thread {
override def run() = try {
mainObject.main(input)
} catch {
// Capture the exception to check whether the exception contains searchString or not
case e: Exception => exception = e
try {
@volatile var exception: Exception = null
val thread = new Thread {
override def run() = try {
mainObject.main(input)
} catch {
// Capture the exception to check whether the exception contains searchString or not
case e: Exception => exception = e
}
}
}
thread.start()
thread.join()
if (exitedCleanly) {
val joined = printStream.lineBuffer.mkString("\n")
assert(joined.contains(searchString))
} else {
assert(exception != null)
if (!exception.getMessage.contains(searchString)) {
throw exception
thread.start()
thread.join()
if (exitedCleanly) {
val joined = printStream.lineBuffer.mkString("\n")
assert(joined.contains(searchString))
} else {
assert(exception != null)
if (!exception.getMessage.contains(searchString)) {
throw exception
}
}
} finally {
mainObject.exitFn = original
}
}
}
Expand Down

0 comments on commit cfaf233

Please sign in to comment.