Skip to content

Commit 449bb12

Browse files
committed
move WithTimeout after wait.before execution
Signed-off-by: Jay Pipes <[email protected]>
1 parent 3cee839 commit 449bb12

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

plugin/exec/eval_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,22 @@ func TestExecOnFail(t *testing.T) {
376376
require.Contains(debugout, "assertion failed: not equal: expected dat but got cat")
377377
require.Contains(debugout, "echo [bad kitty]")
378378
}
379+
380+
func TestTimeoutWithWait(t *testing.T) {
381+
require := require.New(t)
382+
383+
fp := filepath.Join("testdata", "timeout-with-wait.yaml")
384+
f, err := os.Open(fp)
385+
require.Nil(err)
386+
387+
s, err := scenario.FromReader(
388+
f,
389+
scenario.WithPath(fp),
390+
)
391+
require.Nil(err)
392+
require.NotNil(s)
393+
394+
ctx := gdtcontext.New(gdtcontext.WithDebug())
395+
err = s.Run(ctx, t)
396+
require.Nil(err)
397+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: timeout-with-wait
2+
description: a scenario that waits and the wait time should not be included in the timeout
3+
tests:
4+
- exec: sleep .50
5+
wait:
6+
# The timeout should NOT fire because sleep .50 should be the only thing
7+
# that is accounted for in the timeout, not the wait.before
8+
before: .5s
9+
timeout:
10+
after: 1s

scenario/run.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error {
9191
rt := getRetry(specCtx, scDefaults, plugin, spec)
9292

9393
to := getTimeout(specCtx, scDefaults, plugin, spec)
94-
if to != nil {
95-
specCtx, specCancel = context.WithTimeout(specCtx, to.Duration())
96-
}
9794

9895
var res *api.Result
9996
ch := make(chan runSpecRes, 1)
@@ -104,6 +101,10 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error {
104101
time.Sleep(wait.BeforeDuration())
105102
}
106103

104+
if to != nil {
105+
specCtx, specCancel = context.WithTimeout(specCtx, to.Duration())
106+
}
107+
107108
go s.runSpec(specCtx, ch, rt, idx, spec)
108109

109110
select {

0 commit comments

Comments
 (0)