yaooqinn commented on code in PR #46028:
URL: https://github.com/apache/spark/pull/46028#discussion_r1569912440
##########
core/src/test/scala/org/apache/spark/util/ThreadUtilsSuite.scala:
##########
@@ -128,6 +128,42 @@ class ThreadUtilsSuite extends SparkFunSuite {
)
}
+ test("wrapCallerStacktrace") {
+ var runnerThreadName: String = null
+ var exception: Throwable = null
+ val t = new Thread() {
+ override def run(): Unit = {
+ runnerThreadName = Thread.currentThread().getName
+ internalMethod()
+ }
+ private def internalMethod(): Unit = {
+ throw new RuntimeException(s"Error occurred on $runnerThreadName")
+ }
+ }
+ t.setDaemon(true)
+ t.setUncaughtExceptionHandler { case (_, e) => exception = e }
+ t.start()
+ t.join()
+
+ ThreadUtils.wrapCallerStacktrace(exception, s"run in separate thread:
$runnerThreadName")
+
+ assert(exception.getStackTrace.mkString("\n").contains(
+ "internalMethod"),
+ "stack trace does not contain real exception stack trace"
+ )
+ assert(exception.getStackTrace.mkString("\n").contains(
+ s"... run in separate thread: $runnerThreadName ..."),
+ "stack trace does not contain expected place holder"
+ )
+ assert(exception.getStackTrace.mkString("\n").contains(
+ "org.scalatest.Suite.run"),
+ "stack trace does not contain caller stack trace"
+ )
+
assert(exception.getStackTrace.mkString("\n").contains("ThreadUtils.scala") ===
false,
Review Comment:
nit: !exception.getStackTrace.mkString("\n").contains("ThreadUtils.scala")
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]