Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move WithTimeout after wait.before execution #42

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading