Skip to content

Commit ab02c23

Browse files
committed
Simplify
1 parent af76f94 commit ab02c23

File tree

1 file changed

+4
-25
lines changed

1 file changed

+4
-25
lines changed

pty/ptytest/ptytest.go

+4-25
Original file line numberDiff line numberDiff line change
@@ -72,35 +72,14 @@ 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-
type message struct {
76-
name string
77-
err error
78-
}
79-
closeC := make(chan message, 2)
80-
doClose := func(name string, c io.Closer) {
81-
select {
82-
case <-ctx.Done():
83-
case closeC <- message{name: name, err: c.Close()}:
84-
}
85-
}
86-
// Close the tty asynchronously to allow the select below to timeout.
87-
go func() {
88-
// Close the tty first so allow out to consume its last bytes.
89-
doClose("ptty", ptty)
90-
doClose("stdbuf", out)
91-
}()
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+
assert.NoError(t, err, "close pty")
9279

93-
More:
9480
select {
9581
case <-ctx.Done():
9682
fatalf(t, name, "cleanup", "copy did not close in time")
97-
case m := <-closeC:
98-
if m.err != nil {
99-
logf(t, name, "copy close error: %s: %v", m.name, m.err)
100-
} else {
101-
logf(t, name, "copy closed: %s", m.name)
102-
}
103-
goto More
10483
case <-copyDone:
10584
}
10685
})

0 commit comments

Comments
 (0)