Skip to content

Commit

Permalink
Try to catch UnsupportedOperationException when calling Thread's stop…
Browse files Browse the repository at this point in the history
…, and try to call method interrupt when that happens as next attempt to stop the running thread. This unblocks the ConductorSuite when runs using JDK 21.
  • Loading branch information
cheeseng committed Sep 24, 2023
1 parent bbc03be commit f1e2005
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 10 additions & 3 deletions jvm/core/src/main/scala/org/scalatest/concurrent/Conductors.scala
Expand Up @@ -1048,10 +1048,17 @@ trait Conductors extends PatienceConfiguration {
// TIMED_WAITING. (BLOCKED is waiting for a lock. WAITING is in the wait set.)
while (threadGroup.areAnyThreadsAlive) {
if (!firstExceptionThrown.isEmpty) {
// If any exception has been thrown, stop any live test thread.
// If any exception has been thrown, stop or interrupt any live test thread.
threadGroup.getThreads.foreach { t =>
if (t.isAlive)
t.stop()
if (t.isAlive) {
try{
t.stop()
}
catch {
case _: UnsupportedOperationException => t.interrupt()
}

}
}
}
// If any threads are in the RUNNABLE state, just check to see if there's been
Expand Down
Expand Up @@ -267,6 +267,9 @@ class ConductorSuite extends AnyFunSuite with Matchers with Conductors with Seve
case t: ThreadDeath =>
threadWasKilled.set(true)
throw t
case t: InterruptedException =>
threadWasKilled.set(true)
throw t
}
}
thread {
Expand Down

0 comments on commit f1e2005

Please sign in to comment.