Skip to content

Commit

Permalink
test_helpers: use an intermediate pipe for subprocess stdout
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rfjakob committed Feb 28, 2018
1 parent b96e3ee commit 48d5f10
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tests/test_helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 48d5f10

Please sign in to comment.