Skip to content

fix(step): measure step.duration from the first retry attempt (#5774) - #5775

Merged
DenysKuchma merged 2 commits into
codeceptjs:4.xfrom
mirao:fix/step-duration-retries-5774
Oct 30, 2026
Merged

DenysKuchma merged 2 commits into
codeceptjs:4.xfrom
mirao:fix/step-duration-retries-5774

Conversation

@mirao

@mirao mirao commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5774

Problem

When a step is retried (e.g. by retryFailedStep), step.duration covers only the last attempt. recordStep() keeps the start time of the first attempt, but HelperStep.run() and FuncStep.run() overwrote startTime on every attempt. A step retried for ~50 s was reported as 3 ms.

Changes

  • lib/step/helper.js, lib/step/func.js: set startTime in run() only when it isn't already set.

Side effect

The global test timeout (lib/listener/globalTimeout.js) now counts time spent on retry attempts:

  • After each step, step.duration is subtracted from the remaining test timeout. Previously only the last attempt was subtracted, so a test with retried steps could run well past its configured timeout. Now such a test fails with TestTimeoutError once retries use up the timeout.
  • The Date.now() - step.startTime check that chooses between TestTimeoutError and StepTimeoutError also includes earlier attempts.

Tests

  • test/unit/steps_test.js: Step and FuncStep keep the first attempt's start time when run again.
  • test/unit/actor_test.js: a step that fails twice and is retried with a 100 ms delay reports step.duration ≥ 190 ms in event.step.finished.
  • All 3 new tests fail without the fix.

🤖 Generated with Claude Code

mirao and others added 2 commits October 30, 2026 08:50
…ptjs#5774)

HelperStep.run() and FuncStep.run() overwrote startTime on every attempt,
so a retried step reported only the duration of its last attempt. Keep the
start time of the first attempt, as recordStep() already intends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The global recorder.retry() rule stayed registered after the test and
retried errors in later test files (AsyncWrapper tests failed in CI).
step.retry() removes its rule once the step finishes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DenysKuchma

Copy link
Copy Markdown
Collaborator

Look nice, thank you

@DenysKuchma
DenysKuchma merged commit 744dba8 into codeceptjs:4.x Oct 30, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

step.duration reflects only the last retry attempt (HelperStep.run() overwrites startTime)

2 participants