Thread dump on test timeout (#8785)

This commit is contained in:
Hubert Plociniczak 2024-01-17 12:20:38 +01:00 committed by GitHub
parent 080690b3ad
commit 7d56cdc234
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -115,7 +115,31 @@ abstract class JsonRpcServerTestKit
def send(json: Json): Unit = send(json.noSpaces)
def expectMessage(timeout: FiniteDuration = 5.seconds.dilated): String = {
val message = outActor.expectMsgClass[String](timeout, classOf[String])
val message =
try {
outActor.expectMsgClass[String](timeout, classOf[String])
} catch {
case e: AssertionError if e.getMessage.contains("timeout") =>
val sb = new StringBuilder(
"Thread dump when timeout is reached while waiting for the message:\n"
)
Thread.getAllStackTraces.entrySet.forEach { entry =>
sb.append(entry.getKey.getName).append("\n")
entry.getValue.foreach { e =>
sb.append(" ")
.append(e.getClassName)
.append(".")
.append(e.getMethodName)
.append("(")
.append(e.getFileName)
.append(":")
.append(e.getLineNumber)
.append(")\n")
}
}
println(sb.toString())
throw e
}
if (debugMessages) println(message)
message
}