diff --git a/plugin/exec/eval_test.go b/plugin/exec/eval_test.go index f433ea2..60f40e8 100644 --- a/plugin/exec/eval_test.go +++ b/plugin/exec/eval_test.go @@ -376,3 +376,22 @@ func TestExecOnFail(t *testing.T) { require.Contains(debugout, "assertion failed: not equal: expected dat but got cat") require.Contains(debugout, "echo [bad kitty]") } + +func TestTimeoutWithWait(t *testing.T) { + require := require.New(t) + + fp := filepath.Join("testdata", "timeout-with-wait.yaml") + f, err := os.Open(fp) + require.Nil(err) + + s, err := scenario.FromReader( + f, + scenario.WithPath(fp), + ) + require.Nil(err) + require.NotNil(s) + + ctx := gdtcontext.New(gdtcontext.WithDebug()) + err = s.Run(ctx, t) + require.Nil(err) +} diff --git a/plugin/exec/testdata/timeout-with-wait.yaml b/plugin/exec/testdata/timeout-with-wait.yaml new file mode 100644 index 0000000..3beafa2 --- /dev/null +++ b/plugin/exec/testdata/timeout-with-wait.yaml @@ -0,0 +1,10 @@ +name: timeout-with-wait +description: a scenario that waits and the wait time should not be included in the timeout +tests: + - exec: sleep .50 + wait: + # The timeout should NOT fire because sleep .50 should be the only thing + # that is accounted for in the timeout, not the wait.before + before: .5s + timeout: + after: 1s diff --git a/scenario/run.go b/scenario/run.go index a2386d4..5b38588 100644 --- a/scenario/run.go +++ b/scenario/run.go @@ -91,9 +91,6 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error { rt := getRetry(specCtx, scDefaults, plugin, spec) to := getTimeout(specCtx, scDefaults, plugin, spec) - if to != nil { - specCtx, specCancel = context.WithTimeout(specCtx, to.Duration()) - } var res *api.Result ch := make(chan runSpecRes, 1) @@ -104,6 +101,10 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error { time.Sleep(wait.BeforeDuration()) } + if to != nil { + specCtx, specCancel = context.WithTimeout(specCtx, to.Duration()) + } + go s.runSpec(specCtx, ch, rt, idx, spec) select {