Skip to content

Commit dfe8488

Browse files
committedApr 3, 2025
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 9010ff1 commit dfe8488

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed
 

Diff for: ‎mod/tigron/internal/com/command_test.go

+4-9
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,18 @@ 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)
379-
374+
start := time.Now()
375+
time.Sleep(2 * time.Second)
380376
res, err := command.Wait()
381-
382377
end := time.Now()
383378

384379
assertive.ErrorIs(t, err, com.ErrTimeout, "Err")
385380
assertive.IsEqual(t, res.ExitCode, -1, "ExitCode")
386381
assertive.IsEqual(t, res.Stdout, "one", "Stdout")
387382
assertive.IsEqual(t, res.Stderr, "", "Stderr")
388-
assertive.IsLessThan(t, end.Sub(start), 2*time.Second, "Total execution time")
383+
assertive.IsLessThan(t, end.Sub(start), 3*time.Second, "Total execution time")
389384
}
390385

391386
func TestPTYStdout(t *testing.T) {

0 commit comments

Comments
 (0)