Skip to content

[SPARK-10564] ThreadingSuite: assertion failures in threads don't fail the test #8723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 45 additions & 23 deletions core/src/test/scala/org/apache/spark/ThreadingSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,30 @@ class ThreadingSuite extends SparkFunSuite with LocalSparkContext with Logging {
val nums = sc.parallelize(1 to 2, 2)
val sem = new Semaphore(0)
ThreadingSuiteState.clear()
var throwable: Option[Throwable] = None
for (i <- 0 until 2) {
new Thread {
override def run() {
val ans = nums.map(number => {
val running = ThreadingSuiteState.runningThreads
running.getAndIncrement()
val time = System.currentTimeMillis()
while (running.get() != 4 && System.currentTimeMillis() < time + 1000) {
Thread.sleep(100)
}
if (running.get() != 4) {
ThreadingSuiteState.failed.set(true)
}
number
}).collect()
assert(ans.toList === List(1, 2))
sem.release()
try {
val ans = nums.map(number => {
val running = ThreadingSuiteState.runningThreads
running.getAndIncrement()
val time = System.currentTimeMillis()
while (running.get() != 4 && System.currentTimeMillis() < time + 1000) {
Thread.sleep(100)
}
if (running.get() != 4) {
ThreadingSuiteState.failed.set(true)
}
number
}).collect()
assert(ans.toList === List(1, 2))
} catch {
case t: Throwable =>
throwable = Some(t)
} finally {
sem.release()
}
}
}.start()
}
Expand All @@ -145,18 +152,25 @@ class ThreadingSuite extends SparkFunSuite with LocalSparkContext with Logging {
ThreadingSuiteState.runningThreads.get() + "); failing test")
fail("One or more threads didn't see runningThreads = 4")
}
throwable.foreach { t => throw t }
}

test("set local properties in different thread") {
sc = new SparkContext("local", "test")
val sem = new Semaphore(0)

var throwable: Option[Throwable] = None
val threads = (1 to 5).map { i =>
new Thread() {
override def run() {
sc.setLocalProperty("test", i.toString)
assert(sc.getLocalProperty("test") === i.toString)
sem.release()
try {
sc.setLocalProperty("test", i.toString)
assert(sc.getLocalProperty("test") === i.toString)
} catch {
case t: Throwable =>
throwable = Some(t)
} finally {
sem.release()
}
}
}
}
Expand All @@ -165,20 +179,27 @@ class ThreadingSuite extends SparkFunSuite with LocalSparkContext with Logging {

sem.acquire(5)
assert(sc.getLocalProperty("test") === null)
throwable.foreach { t => throw t }
}

test("set and get local properties in parent-children thread") {
sc = new SparkContext("local", "test")
sc.setLocalProperty("test", "parent")
val sem = new Semaphore(0)

var throwable: Option[Throwable] = None
val threads = (1 to 5).map { i =>
new Thread() {
override def run() {
assert(sc.getLocalProperty("test") === "parent")
sc.setLocalProperty("test", i.toString)
assert(sc.getLocalProperty("test") === i.toString)
sem.release()
try {
assert(sc.getLocalProperty("test") === "parent")
sc.setLocalProperty("test", i.toString)
assert(sc.getLocalProperty("test") === i.toString)
} catch {
case t: Throwable =>
throwable = Some(t)
} finally {
sem.release()
}
}
}
}
Expand All @@ -188,6 +209,7 @@ class ThreadingSuite extends SparkFunSuite with LocalSparkContext with Logging {
sem.acquire(5)
assert(sc.getLocalProperty("test") === "parent")
assert(sc.getLocalProperty("Foo") === null)
throwable.foreach { t => throw t }
}

test("mutations to local properties should not affect submitted jobs (SPARK-6629)") {
Expand Down