From 48d5f10c791be37810ae3d880f84140a4122911c Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Wed, 28 Feb 2018 20:03:54 +0100 Subject: 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 --- tests/test_helpers/helpers.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'tests/test_helpers') 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() -- cgit v1.2.3