Commit c06b10ae authored by Ian Lance Taylor's avatar Ian Lance Taylor

os/exec: fix race in TestStdinCloseRace

The test for the race detector itself had a race of a sort not
detected by the race detector.

Fixes #18286.

Change-Id: I3265eae275aaa2869a6b6d3e8675b0d88b25831b
Reviewed-on: https://go-review.googlesource.com/34287Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent d986daec
......@@ -247,6 +247,11 @@ func TestStdinClose(t *testing.T) {
}
// Issue 17647.
// It used to be the case that TestStdinClose, above, would fail when
// run under the race detector. This test is a variant of TestStdinClose
// that also used to fail when run under the race detector.
// This test is run by cmd/dist under the race detector to verify that
// the race detector no longer reports any problems.
func TestStdinCloseRace(t *testing.T) {
cmd := helperCommand(t, "stdinClose")
stdin, err := cmd.StdinPipe()
......@@ -262,7 +267,12 @@ func TestStdinCloseRace(t *testing.T) {
}
}()
go func() {
io.Copy(stdin, strings.NewReader(stdinCloseTestString))
// Send the wrong string, so that the child fails even
// if the other goroutine doesn't manage to kill it first.
// This test is to check that the race detector does not
// falsely report an error, so it doesn't matter how the
// child process fails.
io.Copy(stdin, strings.NewReader("unexpected string"))
if err := stdin.Close(); err != nil {
t.Errorf("stdin.Close: %v", err)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment