Skip to content

Commit ba9dacc

Browse files
authored
Merge pull request scala#5998 from retronym/review/5918
PipedSource should join Source thread to wait the exit value.
2 parents 0dc2c3d + d64cf9e commit ba9dacc

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/library/scala/sys/process/ProcessImpl.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ private[process] trait ProcessImpl {
147147
throw err
148148
}
149149
runInterruptible {
150+
source.join()
150151
val exit1 = first.exitValue()
151152
val exit2 = second.exitValue()
152153
// Since file redirection (e.g. #>) is implemented as a piped process,

test/junit/scala/sys/process/PipedProcessTest.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import java.lang.reflect.InvocationTargetException
99
import scala.concurrent.{Await, Future}
1010
import scala.concurrent.ExecutionContext.Implicits.global
1111
import scala.util.control.Exception.ignoring
12+
import org.junit.Assert.assertEquals
1213

1314
// Each test normally ends in a moment, but for failure cases, waits two seconds.
1415
// scala/bug#7350, scala/bug#8768
@@ -94,6 +95,24 @@ class PipedProcessTest {
9495
assert(b.destroyCount == 0)
9596
}
9697

98+
@Test
99+
def shouldSyncRunAndExitValue() {
100+
val io = BasicIO(false, ProcessLogger(_ => ()))
101+
val source = new PipeSourceMock {
102+
override def run(): Unit = {
103+
Thread.sleep(5) //used to simulate the block
104+
}
105+
}
106+
val sink = new PipeSinkMock
107+
val a = new ProcessMock(error = false)
108+
val b = new ProcessMock(error = false)
109+
val p = new PipedProcesses(new ProcessBuilderMock(a, error = false), new ProcessBuilderMock(b, error = false), io, false)
110+
111+
p.callRunAndExitValue(source, sink)
112+
113+
assertEquals(false, source.isAlive)
114+
}
115+
97116
// PipedProcesses must release resources when b.run() failed
98117
@Test
99118
def bFailed() {

0 commit comments

Comments
 (0)