Merge pull request #8180 from eed3si9n/wip/wait

fix: Use promise to wait for forked test
This commit is contained in:
eugene yokota
2025-08-02 15:31:46 -04:00
committed by GitHub
@@ -11,13 +11,14 @@ package internal
import com.google.gson.Gson import com.google.gson.Gson
import java.io.* import java.io.*
import java.util.concurrent.atomic.AtomicReference
import sbt.io.IO import sbt.io.IO
import sbt.internal.worker1.* import sbt.internal.worker1.*
import sbt.testing.Framework import sbt.testing.Framework
import scala.sys.process.{ BasicIO, Process, ProcessIO } import scala.sys.process.{ BasicIO, Process, ProcessIO }
import scala.collection.mutable import scala.collection.mutable
import scala.collection.mutable.ListBuffer import scala.collection.mutable.ListBuffer
import scala.concurrent.{ Await, Promise }
import scala.concurrent.duration.*
object WorkerExchange: object WorkerExchange:
val listeners: mutable.ListBuffer[WorkerResponseListener] = ListBuffer.empty val listeners: mutable.ListBuffer[WorkerResponseListener] = ListBuffer.empty
@@ -36,15 +37,17 @@ object WorkerExchange:
fullCp.mkString(File.pathSeparator), fullCp.mkString(File.pathSeparator),
classOf[WorkerMain].getCanonicalName, classOf[WorkerMain].getCanonicalName,
) )
val inputRef = AtomicReference[OutputStream]() val inputRef = Promise[OutputStream]()
val processIo = ProcessIO( val processIo = ProcessIO(
in = (input) => inputRef.set(input), in = (input) => inputRef.success(input),
out = BasicIO.processFully(onStdoutLine), out = BasicIO.processFully(onStdoutLine),
err = BasicIO.processFully((line) => scala.Console.err.println(line)), err = BasicIO.processFully((line) => scala.Console.err.println(line)),
) )
val forkWithIo = fo.withOutputStrategy(OutputStrategy.CustomInputOutput(processIo)) val forkWithIo = fo.withOutputStrategy(OutputStrategy.CustomInputOutput(processIo))
val p = Fork.java.fork(forkWithIo, options) val p = Fork.java.fork(forkWithIo, options)
WorkerProxy(inputRef.get(), p, options) val forkTimeout = 30.seconds
val input = Await.result(inputRef.future, forkTimeout)
WorkerProxy(input, p, options)
def registerListener(listener: WorkerResponseListener): Unit = def registerListener(listener: WorkerResponseListener): Unit =
synchronized: synchronized: