MINOR: Add more information in assertion failure for non daemon threads (#13858)

Reviewers: Luke Chen <showuon@gmail.com>
This commit is contained in:
Divij Vaidya 2023-06-16 15:17:57 +02:00 committed by GitHub
parent 74238656dc
commit b10beaae77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -1341,10 +1341,12 @@ object TestUtils extends Logging {
// Note: Call this method in the test itself, rather than the @AfterEach method. // Note: Call this method in the test itself, rather than the @AfterEach method.
// Because of the assert, if assertNoNonDaemonThreads fails, nothing after would be executed. // Because of the assert, if assertNoNonDaemonThreads fails, nothing after would be executed.
def assertNoNonDaemonThreads(threadNamePrefix: String): Unit = { def assertNoNonDaemonThreads(threadNamePrefix: String): Unit = {
val threadCount = Thread.getAllStackTraces.keySet.asScala.count { t => val nonDaemonThreads = Thread.getAllStackTraces.keySet.asScala.filter { t =>
!t.isDaemon && t.isAlive && t.getName.startsWith(threadNamePrefix) !t.isDaemon && t.isAlive && t.getName.startsWith(threadNamePrefix)
} }
assertEquals(0, threadCount)
val threadCount = nonDaemonThreads.size
assertEquals(0, threadCount, s"Found unexpected $threadCount NonDaemon threads=${nonDaemonThreads.map(t => t.getName).mkString(", ")}")
} }
def allThreadStackTraces(): String = { def allThreadStackTraces(): String = {