diff options
author | Jakob Unterwurzacher | 2018-02-28 20:03:54 +0100 |
---|---|---|
committer | Jakob Unterwurzacher | 2018-02-28 20:03:54 +0100 |
commit | 48d5f10c791be37810ae3d880f84140a4122911c (patch) | |
tree | 184bdfa6447dd69a5b6c07f2cbd1e40b142a1710 /tests/test_helpers | |
parent | b96e3ee2717531e842c492c3a6799d1d0c3e51cb (diff) |
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
https://github.com/rfjakob/gocryptfs/issues/213
Diffstat (limited to 'tests/test_helpers')
-rw-r--r-- | tests/test_helpers/helpers.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go index 778fd3a..47517a6 100644 --- a/tests/test_helpers/helpers.go +++ b/tests/test_helpers/helpers.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "io" "io/ioutil" "log" "net" @@ -157,8 +158,17 @@ func Mount(c string, p string, showOutput bool, extraArgs ...string) error { cmd := exec.Command(GocryptfsBinary, args...) if showOutput { - cmd.Stderr = os.Stderr - cmd.Stdout = os.Stdout + // The Go test logic waits for our stdout to close, and when we share + // it with the subprocess, it will wait for it to close it as well. + // Use an intermediate pipe so the tests do not hang when unmouting + // fails. + pr, pw, err := os.Pipe() + if err != nil { + return err + } + cmd.Stderr = pw + cmd.Stdout = pw + go func() { io.Copy(os.Stdout, pr) }() } return cmd.Run() |