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

js: Return the new deadline error when running code #3399

Merged
merged 1 commit into from
Oct 16, 2023
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
32 changes: 32 additions & 0 deletions cmd/tests/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2223,3 +2223,35 @@ func TestBrowserPermissions(t *testing.T) {
})
}
}

func TestSetupTimeout(t *testing.T) {
t.Parallel()
ts := NewGlobalTestState(t)
ts.ExpectedExitCode = int(exitcodes.SetupTimeout)
ts.CmdArgs = []string{"k6", "run", "-"}
ts.Stdin = bytes.NewBufferString(`
import { sleep } from 'k6';

export const options = {
setupTimeout: '1s',
};

export function setup() { sleep(100000); };
export default function() {}
`)

start := time.Now()
cmd.ExecuteWithGlobalState(ts.GlobalState)
elapsed := time.Since(start)
assert.Greater(t, elapsed, 1*time.Second, "expected more time to have passed because of setupTimeout")
assert.Less(
t, elapsed, 2*time.Second,
"expected less time to have passed because setupTimeout ",
)

stdout := ts.Stdout.String()
t.Log(stdout)
stderr := ts.Stderr.String()
t.Log(stderr)
assert.Contains(t, stderr, "setup() execution timed out after 1 seconds")
}
4 changes: 2 additions & 2 deletions js/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func (r *Runner) HandleSummary(ctx context.Context, summary *lib.Summary) (map[s
rawResult, _, _, err := vu.runFn(summaryCtx, false, handleSummaryWrapper, nil, wrapperArgs...)

if deadlineError := r.checkDeadline(summaryCtx, consts.HandleSummaryFn, rawResult, err); deadlineError != nil {
return nil, err
return nil, deadlineError
}

if err != nil {
Expand Down Expand Up @@ -573,7 +573,7 @@ func (r *Runner) runPart(
v, _, _, err := vu.runFn(ctx, false, fn, nil, vu.Runtime.ToValue(arg))

if deadlineError := r.checkDeadline(ctx, name, v, err); deadlineError != nil {
return nil, err
return nil, deadlineError
}

return v, err
Expand Down