Skip to content

Commit 48d5f10

Browse files
committed
test_helpers: use an intermediate pipe for subprocess stdout
To Go test logic waits for stderr and stdout to close, so when we share it with a subprocess, it will wait for it to exit as well. We don't want the tests to hang when the unmount fails. Seen on MacOS as reported at #213
1 parent b96e3ee commit 48d5f10

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

tests/test_helpers/helpers.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/hex"
77
"encoding/json"
88
"fmt"
9+
"io"
910
"io/ioutil"
1011
"log"
1112
"net"
@@ -157,8 +158,17 @@ func Mount(c string, p string, showOutput bool, extraArgs ...string) error {
157158

158159
cmd := exec.Command(GocryptfsBinary, args...)
159160
if showOutput {
160-
cmd.Stderr = os.Stderr
161-
cmd.Stdout = os.Stdout
161+
// The Go test logic waits for our stdout to close, and when we share
162+
// it with the subprocess, it will wait for it to close it as well.
163+
// Use an intermediate pipe so the tests do not hang when unmouting
164+
// fails.
165+
pr, pw, err := os.Pipe()
166+
if err != nil {
167+
return err
168+
}
169+
cmd.Stderr = pw
170+
cmd.Stdout = pw
171+
go func() { io.Copy(os.Stdout, pr) }()
162172
}
163173

164174
return cmd.Run()

0 commit comments

Comments
 (0)