From 479099fed24c265b65e5f63acd75945d6d5ca663 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Mon, 16 Oct 2023 19:02:26 +0300 Subject: [PATCH] js: Return the new deadline error when running code This was mistakenly broken in 7b5aaaa0 --- cmd/tests/cmd_run_test.go | 32 ++++++++++++++++++++++++++++++++ js/runner.go | 4 ++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/cmd/tests/cmd_run_test.go b/cmd/tests/cmd_run_test.go index cd2d57d68a0..618bd87453c 100644 --- a/cmd/tests/cmd_run_test.go +++ b/cmd/tests/cmd_run_test.go @@ -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") +} diff --git a/js/runner.go b/js/runner.go index 7f9c7fcb5ac..3a010882793 100644 --- a/js/runner.go +++ b/js/runner.go @@ -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 { @@ -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