fix: Close tty first in `ptytest` cleanup (#5252)

This commit is contained in:
Mathias Fredriksson 2022-12-02 14:32:50 +02:00 committed by GitHub
parent ee4f0fc592
commit 81c3948792
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -107,6 +107,7 @@
"slogtest",
"sourcemapped",
"Srcs",
"stdbuf",
"stretchr",
"STTY",
"stuntest",

View File

@ -72,8 +72,13 @@ func create(t *testing.T, ptty pty.PTY, name string) *PTY {
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
defer cancel()
_ = out.Close()
_ = ptty.Close()
// Close pty only so that the copy goroutine can consume the
// remainder of it's buffer and then exit.
err := ptty.Close()
// Pty may already be closed, so don't fail the test, but log
// the error in case it's significant.
logf(t, name, "closed pty: %v", err)
select {
case <-ctx.Done():
fatalf(t, name, "cleanup", "copy did not close in time")