From 5ecd26d369877e48142cc0b7f769ecada28f59d2 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Fri, 6 Aug 2021 14:24:28 +0200 Subject: [PATCH] Fix CoronerSpec instability (#30494) Tested in https://github.com/akka/akka/pull/30437 that indeed looking at the threads 'too soon' might miss the deadlock. --- akka-testkit/src/test/scala/akka/testkit/Coroner.scala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/akka-testkit/src/test/scala/akka/testkit/Coroner.scala b/akka-testkit/src/test/scala/akka/testkit/Coroner.scala index 675d8e6ffa..40e5126579 100644 --- a/akka-testkit/src/test/scala/akka/testkit/Coroner.scala +++ b/akka-testkit/src/test/scala/akka/testkit/Coroner.scala @@ -144,6 +144,11 @@ object Coroner { #Heap usage: ${memMx.getHeapMemoryUsage()} #Non-heap usage: ${memMx.getNonHeapMemoryUsage()}""".stripMargin('#')) + // If we look too soon, we've seen the JVM report a thread + // (in that case deadlock-thread-a from CoronerSpec) + // waiting on the lock while no thread seemed to be holding it + Thread.sleep(300) + def dumpAllThreads: Seq[ThreadInfo] = threadMx.dumpAllThreads(threadMx.isObjectMonitorUsageSupported, threadMx.isSynchronizerUsageSupported).toSeq