Skip to content

Commit b9eecf1

Browse files
committed
Adjust command test
In some cases, exec is just really slow. Adjusting tests so that we start counting after the command actually started. Signed-off-by: apostasie <[email protected]>
1 parent 2f2f8e6 commit b9eecf1

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

mod/tigron/internal/com/command_test.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ func TestStdoutStderr(t *testing.T) {
335335
func TestTimeoutPlain(t *testing.T) {
336336
t.Parallel()
337337

338-
start := time.Now()
339338
command := &com.Command{
340339
Binary: "bash",
341340
// XXX unclear if windows is really able to terminate sleep 5, so, split it up to give it a
@@ -345,11 +344,10 @@ func TestTimeoutPlain(t *testing.T) {
345344
}
346345

347346
err := command.Run(context.WithValue(context.Background(), com.LoggerKey, t))
348-
349347
assertive.ErrorIsNil(t, err, "Err")
350348

349+
start := time.Now()
351350
res, err := command.Wait()
352-
353351
end := time.Now()
354352

355353
assertive.ErrorIs(t, err, com.ErrTimeout, "Err")
@@ -362,7 +360,6 @@ func TestTimeoutPlain(t *testing.T) {
362360
func TestTimeoutDelayed(t *testing.T) {
363361
t.Parallel()
364362

365-
start := time.Now()
366363
command := &com.Command{
367364
Binary: "bash",
368365
// XXX unclear if windows is really able to terminate sleep 5, so, split it up to give it a
@@ -372,20 +369,20 @@ func TestTimeoutDelayed(t *testing.T) {
372369
}
373370

374371
err := command.Run(context.WithValue(context.Background(), com.LoggerKey, t))
375-
376372
assertive.ErrorIsNil(t, err, "Err")
377373

378-
time.Sleep(1 * time.Second)
374+
start := time.Now()
379375

380-
res, err := command.Wait()
376+
time.Sleep(2 * time.Second)
381377

378+
res, err := command.Wait()
382379
end := time.Now()
383380

384381
assertive.ErrorIs(t, err, com.ErrTimeout, "Err")
385382
assertive.IsEqual(t, res.ExitCode, -1, "ExitCode")
386383
assertive.IsEqual(t, res.Stdout, "one", "Stdout")
387384
assertive.IsEqual(t, res.Stderr, "", "Stderr")
388-
assertive.IsLessThan(t, end.Sub(start), 2*time.Second, "Total execution time")
385+
assertive.IsLessThan(t, end.Sub(start), 3*time.Second, "Total execution time")
389386
}
390387

391388
func TestPTYStdout(t *testing.T) {

0 commit comments

Comments
 (0)