fix: prevent test flake by waiting on copy ()

This commit is contained in:
Mathias Fredriksson 2024-08-12 12:54:30 +03:00 committed by GitHub
commit a2a5fcf79b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -135,17 +135,19 @@ func startSSHServer(ctx context.Context, t testing.TB) string {
_, _ = io.Copy(in, s) _, _ = io.Copy(in, s)
_ = in.Close() _ = in.Close()
}() }()
outCopyDone := make(chan struct{})
go func() { go func() {
_, _ = io.Copy(s, out) _, _ = io.Copy(s, out)
_ = out.Close() _ = out.Close()
_ = s.CloseWrite() close(outCopyDone)
}() }()
err = cmd.Wait() err = cmd.Wait()
if err != nil { if err != nil {
t.Logf("command failed: %s", err) t.Logf("command failed: %s", err)
} }
<-outCopyDone
t.Logf("session ended: %s", s.RawCommand()) t.Logf("session ended (cmd=%q, code=%d)", s.RawCommand(), cmd.ProcessState.ExitCode())
err = s.Exit(cmd.ProcessState.ExitCode()) err = s.Exit(cmd.ProcessState.ExitCode())
if err != nil { if err != nil {