Skip to content

Commit

Permalink
Merge pull request #42 from jaypipes/panic-at-the-disco
Browse files Browse the repository at this point in the history
move WithTimeout after wait.before execution
  • Loading branch information
jaypipes committed Jun 26, 2024
2 parents d0660bd + 449bb12 commit 3b6bfd3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
19 changes: 19 additions & 0 deletions plugin/exec/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
10 changes: 10 additions & 0 deletions plugin/exec/testdata/timeout-with-wait.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions scenario/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 3b6bfd3

Please sign in to comment.