Skip to content

Commit 2f3ff6c

Browse files
authored
fix: improve pty and ptytest (#5327)
* Fix: improve ptytest * Disable skip * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * Fix * WIP * Fix * fix: pty close on Windows * Revert changes around workflow * fix
1 parent 161465d commit 2f3ff6c

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

pty/pty_windows.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,16 @@ func (p *ptyWindows) Close() error {
130130
return nil
131131
}
132132
p.closed = true
133-
_ = p.outputWrite.Close()
134-
_ = p.outputRead.Close()
135-
_ = p.inputWrite.Close()
136-
_ = p.inputRead.Close()
137133

138134
ret, _, err := procClosePseudoConsole.Call(uintptr(p.console))
139135
if ret < 0 {
140136
return xerrors.Errorf("close pseudo console: %w", err)
141137
}
142138

139+
_ = p.outputWrite.Close()
140+
_ = p.outputRead.Close()
141+
_ = p.inputWrite.Close()
142+
_ = p.inputRead.Close()
143143
return nil
144144
}
145145

pty/ptytest/ptytest.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ func create(t *testing.T, ptty pty.PTY, name string) *PTY {
5050
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
5151
defer cancel()
5252

53+
logf(t, name, "close logw on cleanup")
5354
_ = logw.Close()
55+
56+
logf(t, name, "close logr on cleanup")
5457
_ = logr.Close()
58+
59+
logf(t, name, "logr and logw closed")
60+
5561
select {
5662
case <-ctx.Done():
5763
fatalf(t, name, "cleanup", "log pipe did not close in time")
@@ -74,6 +80,7 @@ func create(t *testing.T, ptty pty.PTY, name string) *PTY {
7480

7581
// Close pty only so that the copy goroutine can consume the
7682
// remainder of it's buffer and then exit.
83+
logf(t, name, "close pty on cleanup")
7784
err := ptty.Close()
7885
// Pty may already be closed, so don't fail the test, but log
7986
// the error in case it's significant.
@@ -152,7 +159,7 @@ func (p *PTY) ExpectMatch(str string) string {
152159
p.logf("matched %q = %q", str, buffer.String())
153160
return buffer.String()
154161
case <-timeout.Done():
155-
// Ensure gorouine is cleaned up before test exit.
162+
// Ensure goroutine is cleaned up before test exit.
156163
_ = p.out.closeErr(p.Close())
157164
<-match
158165

0 commit comments

Comments
 (0)