From d2685fa2ca3fb1ef2de35b1254a1e8f62ce134e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wro=C5=84ski?= Date: Thu, 17 Nov 2022 15:26:42 +0100 Subject: [PATCH] Use deamon thread instead of non-deamon thread which prevent JVM from exiting --- .../scala/munit/internal/PlatformCompat.scala | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala b/munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala index 276307a0..f56ef6dc 100644 --- a/munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala +++ b/munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala @@ -4,15 +4,30 @@ import scala.concurrent.Future import sbt.testing.Task import sbt.testing.EventHandler import sbt.testing.Logger + import scala.concurrent.duration.Duration -import java.util.concurrent.Executors +import java.util.concurrent.{ + Executors, + ThreadFactory, + TimeUnit, + TimeoutException +} import scala.concurrent.Promise import scala.concurrent.ExecutionContext -import java.util.concurrent.TimeUnit -import java.util.concurrent.TimeoutException +import java.util.concurrent.atomic.AtomicInteger object PlatformCompat { - private val sh = Executors.newSingleThreadScheduledExecutor() + private val sh = Executors.newSingleThreadScheduledExecutor( + new ThreadFactory { + val counter = new AtomicInteger + def threadNumber() = counter.incrementAndGet() + def newThread(r: Runnable) = + new Thread(r, s"munit-scheduler-${threadNumber()}") { + setDaemon(true) + setPriority(Thread.NORM_PRIORITY) + } + } + ) def executeAsync( task: Task, eventHandler: EventHandler,