Skip to content

Commit

Permalink
os: do not close syscall.Stdin in TestReadStdin
Browse files Browse the repository at this point in the history
By calling NewConsoleFile on syscall.Stdin, we wind up closing it when
the function returns, which causes errors when all the tests are run in
a loop. To fix this, we instead create a duplicate handle of stdin.

Fixes #43720.

Change-Id: Ie6426e6306c7e1e39601794f4ff48bbf2fe67502
Reviewed-on: https://go-review.googlesource.com/c/go/+/284140
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
  • Loading branch information
zx2c4 committed Jan 18, 2021
1 parent 682a1d2 commit 5a8fbb0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/os/os_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,16 @@ func TestReadStdin(t *testing.T) {
poll.ReadConsole = old
}()

testConsole := os.NewConsoleFile(syscall.Stdin, "test")
p, err := syscall.GetCurrentProcess()
if err != nil {
t.Fatalf("Unable to get handle to current process: %v", err)
}
var stdinDuplicate syscall.Handle
err = syscall.DuplicateHandle(p, syscall.Handle(syscall.Stdin), p, &stdinDuplicate, 0, false, syscall.DUPLICATE_SAME_ACCESS)
if err != nil {
t.Fatalf("Unable to duplicate stdin: %v", err)
}
testConsole := os.NewConsoleFile(stdinDuplicate, "test")

var tests = []string{
"abc",
Expand Down

0 comments on commit 5a8fbb0

Please sign in to comment.