Skip to content

Commit

Permalink
js: Return the new deadline error when running code
Browse files Browse the repository at this point in the history
This was mistakenly broken in 7b5aaaa
  • Loading branch information
mstoykov committed Oct 16, 2023
1 parent d1d5969 commit 479099f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
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

0 comments on commit 479099f

Please sign in to comment.