mirror of https://github.com/apache/kafka.git
MINOR: Add more information in assertion failure for non daemon threads (#13858)
Reviewers: Luke Chen <showuon@gmail.com>
This commit is contained in:
parent
74238656dc
commit
b10beaae77
|
@ -1341,10 +1341,12 @@ object TestUtils extends Logging {
|
|||
// 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.
|
||||
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)
|
||||
}
|
||||
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 = {
|
||||
|
|
Loading…
Reference in New Issue