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
commit 5c12b605eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 4 deletions

View File

@ -11,13 +11,14 @@ package internal
import com.google.gson.Gson
import java.io.*
import java.util.concurrent.atomic.AtomicReference
import sbt.io.IO
import sbt.internal.worker1.*
import sbt.testing.Framework
import scala.sys.process.{ BasicIO, Process, ProcessIO }
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.concurrent.{ Await, Promise }
import scala.concurrent.duration.*
object WorkerExchange:
val listeners: mutable.ListBuffer[WorkerResponseListener] = ListBuffer.empty
@ -36,15 +37,17 @@ object WorkerExchange:
fullCp.mkString(File.pathSeparator),
classOf[WorkerMain].getCanonicalName,
)
val inputRef = AtomicReference[OutputStream]()
val inputRef = Promise[OutputStream]()
val processIo = ProcessIO(
in = (input) => inputRef.set(input),
in = (input) => inputRef.success(input),
out = BasicIO.processFully(onStdoutLine),
err = BasicIO.processFully((line) => scala.Console.err.println(line)),
)
val forkWithIo = fo.withOutputStrategy(OutputStrategy.CustomInputOutput(processIo))
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 =
synchronized: