From 81c39487924df390f90e774138f207d9f666d120 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 2 Dec 2022 14:32:50 +0200 Subject: [PATCH] fix: Close tty first in `ptytest` cleanup (#5252) --- .vscode/settings.json | 1 + pty/ptytest/ptytest.go | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4a0ab16e55..292ee5cd7c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -107,6 +107,7 @@ "slogtest", "sourcemapped", "Srcs", + "stdbuf", "stretchr", "STTY", "stuntest", diff --git a/pty/ptytest/ptytest.go b/pty/ptytest/ptytest.go index 635176a155..bc26585f29 100644 --- a/pty/ptytest/ptytest.go +++ b/pty/ptytest/ptytest.go @@ -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")