diff options
author | Alex Brainman <alex.brainman@gmail.com> | 2017-05-22 17:17:39 +1000 |
---|---|---|
committer | Alex Brainman <alex.brainman@gmail.com> | 2017-05-23 04:27:01 +0000 |
commit | f3f29d1dea525f48995c1693c609f5e67c046893 (patch) | |
tree | 353048a19ca6b3ba8277c4b823ec85871b6b3555 /src/os/exec/exec_test.go | |
parent | 5f4f7519b6c038ab6771e6c7111bcd29967f2750 (diff) | |
download | go-f3f29d1dea525f48995c1693c609f5e67c046893.tar.gz go-f3f29d1dea525f48995c1693c609f5e67c046893.zip |
os/exec: ignore some pipe write errors on windows
This change is windows version of CL 12152.
It also extends test to cover scenarios reported on issue #20445.
Some source files copied and renamed to make code clearer.
Fixes #20445
Change-Id: Idd2f636f27c6bd5cfe98017ba2df911358263382
Reviewed-on: https://go-review.googlesource.com/43910
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/os/exec/exec_test.go')
-rw-r--r-- | src/os/exec/exec_test.go | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go index 95af597f15..0132906933 100644 --- a/src/os/exec/exec_test.go +++ b/src/os/exec/exec_test.go @@ -877,25 +877,41 @@ func TestHelperProcess(*testing.T) { } } +type delayedInfiniteReader struct{} + +func (delayedInfiniteReader) Read(b []byte) (int, error) { + time.Sleep(100 * time.Millisecond) + for i := range b { + b[i] = 'x' + } + return len(b), nil +} + // Issue 9173: ignore stdin pipe writes if the program completes successfully. func TestIgnorePipeErrorOnSuccess(t *testing.T) { testenv.MustHaveExec(t) - // We really only care about testing this on Unixy things. - if runtime.GOOS == "windows" || runtime.GOOS == "plan9" { + // We really only care about testing this on Unixy and Windowsy things. + if runtime.GOOS == "plan9" { t.Skipf("skipping test on %q", runtime.GOOS) } - cmd := helperCommand(t, "echo", "foo") - var out bytes.Buffer - cmd.Stdin = strings.NewReader(strings.Repeat("x", 10<<20)) - cmd.Stdout = &out - if err := cmd.Run(); err != nil { - t.Fatal(err) - } - if got, want := out.String(), "foo\n"; got != want { - t.Errorf("output = %q; want %q", got, want) + testWith := func(r io.Reader) func(*testing.T) { + return func(t *testing.T) { + cmd := helperCommand(t, "echo", "foo") + var out bytes.Buffer + cmd.Stdin = r + cmd.Stdout = &out + if err := cmd.Run(); err != nil { + t.Fatal(err) + } + if got, want := out.String(), "foo\n"; got != want { + t.Errorf("output = %q; want %q", got, want) + } + } } + t.Run("10MB", testWith(strings.NewReader(strings.Repeat("x", 10<<20)))) + t.Run("Infinite", testWith(delayedInfiniteReader{})) } type badWriter struct{} |