Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 81c3948

Browse files
authored
fix: Close tty first in ptytest cleanup (coder#5252)
1 parent ee4f0fc commit 81c3948

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"slogtest",
108108
"sourcemapped",
109109
"Srcs",
110+
"stdbuf",
110111
"stretchr",
111112
"STTY",
112113
"stuntest",

pty/ptytest/ptytest.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ func create(t *testing.T, ptty pty.PTY, name string) *PTY {
7272
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
7373
defer cancel()
7474

75-
_ = out.Close()
76-
_ = ptty.Close()
75+
// Close pty only so that the copy goroutine can consume the
76+
// remainder of it's buffer and then exit.
77+
err := ptty.Close()
78+
// Pty may already be closed, so don't fail the test, but log
79+
// the error in case it's significant.
80+
logf(t, name, "closed pty: %v", err)
81+
7782
select {
7883
case <-ctx.Done():
7984
fatalf(t, name, "cleanup", "copy did not close in time")

0 commit comments

Comments
 (0)