@@ -47,9 +47,16 @@ func create(t *testing.T, ptty pty.PTY, name string) *PTY {
47
47
logDone := make (chan struct {})
48
48
logr , logw := io .Pipe ()
49
49
t .Cleanup (func () {
50
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitShort )
51
+ defer cancel ()
52
+
50
53
_ = logw .Close ()
51
54
_ = logr .Close ()
52
- <- logDone // Guard against logging after test.
55
+ select {
56
+ case <- ctx .Done ():
57
+ fatalf (t , name , "cleanup" , "log pipe did not close in time" )
58
+ case <- logDone : // Guard against logging after test.
59
+ }
53
60
})
54
61
55
62
// Write to log and output buffer.
@@ -62,9 +69,16 @@ func create(t *testing.T, ptty pty.PTY, name string) *PTY {
62
69
_ = out .closeErr (err )
63
70
}()
64
71
t .Cleanup (func () {
72
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitShort )
73
+ defer cancel ()
74
+
65
75
_ = out .Close ()
66
76
_ = ptty .Close ()
67
- <- copyDone
77
+ select {
78
+ case <- ctx .Done ():
79
+ fatalf (t , name , "cleanup" , "copy did not close in time" )
80
+ case <- copyDone :
81
+ }
68
82
})
69
83
70
84
tpty := & PTY {
@@ -164,20 +178,30 @@ func (p *PTY) WriteLine(str string) {
164
178
165
179
func (p * PTY ) logf (format string , args ... interface {}) {
166
180
p .t .Helper ()
181
+ logf (p .t , p .name , format , args ... )
182
+ }
183
+
184
+ func (p * PTY ) fatalf (reason string , format string , args ... interface {}) {
185
+ p .t .Helper ()
186
+ fatalf (p .t , p .name , reason , format , args ... )
187
+ }
188
+
189
+ func logf (t * testing.T , name , format string , args ... interface {}) {
190
+ t .Helper ()
167
191
168
192
// Match regular logger timestamp format, we seem to be logging in
169
193
// UTC in other places as well, so match here.
170
- p . t .Logf ("%s: %s: %s" , time .Now ().UTC ().Format ("2006-01-02 15:04:05.000" ), p . name , fmt .Sprintf (format , args ... ))
194
+ t .Logf ("%s: %s: %s" , time .Now ().UTC ().Format ("2006-01-02 15:04:05.000" ), name , fmt .Sprintf (format , args ... ))
171
195
}
172
196
173
- func ( p * PTY ) fatalf ( reason string , format string , args ... interface {}) {
174
- p . t .Helper ()
197
+ func fatalf ( t * testing. T , name , reason , format string , args ... interface {}) {
198
+ t .Helper ()
175
199
176
200
// Ensure the message is part of the normal log stream before
177
201
// failing the test.
178
- p . logf ("%s: %s" , reason , fmt .Sprintf (format , args ... ))
202
+ logf (t , name , "%s: %s" , reason , fmt .Sprintf (format , args ... ))
179
203
180
- require .FailNowf (p . t , reason , format , args ... )
204
+ require .FailNowf (t , reason , format , args ... )
181
205
}
182
206
183
207
// stdbuf is like a buffered stdout, it buffers writes until read.
0 commit comments