@@ -257,25 +257,35 @@ func TestCommandTransportTerminateDuration(t *testing.T) {
257257 }
258258 requireExec (t )
259259
260+ // Unfortunately, since it does I/O, this test needs to rely on timing (we
261+ // can't use synctest). However, we can still decreate the default
262+ // termination duration to speed up the test.
263+ const defaultDur = 50 * time .Millisecond
264+ defer mcp .SetDefaultTerminateDuration (defaultDur )()
265+
260266 tests := []struct {
261267 name string
262268 duration time.Duration
269+ wantMinDuration time.Duration
263270 wantMaxDuration time.Duration
264271 }{
265272 {
266273 name : "default duration (zero)" ,
267274 duration : 0 ,
268- wantMaxDuration : 6 * time .Second , // default 5s + buffer
275+ wantMinDuration : defaultDur ,
276+ wantMaxDuration : 1 * time .Second , // default + buffer
269277 },
270278 {
271279 name : "below minimum duration" ,
272- duration : 500 * time .Millisecond ,
273- wantMaxDuration : 6 * time .Second , // should use default 5s + buffer
280+ duration : - 500 * time .Millisecond ,
281+ wantMinDuration : defaultDur ,
282+ wantMaxDuration : 1 * time .Second , // should use default + buffer
274283 },
275284 {
276285 name : "custom valid duration" ,
277- duration : 2 * time .Second ,
278- wantMaxDuration : 3 * time .Second , // custom 2s + buffer
286+ duration : 200 * time .Millisecond ,
287+ wantMinDuration : 200 * time .Millisecond ,
288+ wantMaxDuration : 1 * time .Second , // custom + buffer
279289 },
280290 }
281291
@@ -306,7 +316,9 @@ func TestCommandTransportTerminateDuration(t *testing.T) {
306316 t .Fatalf ("Close() failed with unexpected error: %v" , err )
307317 }
308318 }
309-
319+ if elapsed < tt .wantMinDuration {
320+ t .Errorf ("Close() took %v, expected at least %v" , elapsed , tt .wantMinDuration )
321+ }
310322 if elapsed > tt .wantMaxDuration {
311323 t .Errorf ("Close() took %v, expected at most %v" , elapsed , tt .wantMaxDuration )
312324 }
0 commit comments