Skip to content

fix(expect): don't sleep past the deadline in retry loop#40290

Open
yury-s wants to merge 1 commit intomicrosoft:mainfrom
yury-s:fix-40281
Open

fix(expect): don't sleep past the deadline in retry loop#40290
yury-s wants to merge 1 commit intomicrosoft:mainfrom
yury-s:fix-40281

Conversation

@yury-s
Copy link
Copy Markdown
Member

@yury-s yury-s commented Apr 18, 2026

Summary

  • retryWithProgressAndTimeouts could sleep past the assertion deadline and abort mid-sleep without a final check, so an element that appeared during that last sleep was missed.
  • Clamp each sleep to the remaining budget (minus a small margin for the next action).

Fixes #40281

The retry loop in retryWithProgressAndTimeouts could sleep past the
assertion deadline, aborting mid-sleep without ever performing a final
check. An element appearing during that final sleep was missed even
when the DOM matched before the deadline.

Clamp each sleep to the remaining budget (minus a 100ms margin for the
next action) so the loop always wakes up in time to run another check.

Fixes microsoft#40281
@yury-s yury-s requested a review from dgozman April 18, 2026 00:51
@yury-s
Copy link
Copy Markdown
Member Author

yury-s commented Apr 18, 2026

Not sure we want this

@github-actions
Copy link
Copy Markdown
Contributor

Test results for "tests 1"

6 flaky ⚠️ [chromium-library] › library/video.spec.ts:719 › screencast › should work with video+trace `@chromium-ubuntu-22.04-node20`
⚠️ [chromium-library] › library/popup.spec.ts:261 › should not throw when click closes popup `@chromium-ubuntu-22.04-node22`
⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:1080 › cli codegen › should not throw csp directive violation errors `@firefox-ubuntu-22.04-node20`
⚠️ [firefox-page] › page/page-wait-for-function.spec.ts:104 › should work with strict CSP policy `@firefox-ubuntu-22.04-node20`
⚠️ [webkit-library] › library/video.spec.ts:275 › screencast › should capture navigation `@webkit-ubuntu-22.04-node20`
⚠️ [playwright-test] › ui-mode-test-output.spec.ts:118 › should collapse repeated console messages for test `@ubuntu-latest-node22`

39249 passed, 847 skipped


Merge workflow run.

@github-actions
Copy link
Copy Markdown
Contributor

Test results for "MCP"

13 failed
❌ [chromium] › mcp/cli-json.spec.ts:84 › list after open returns one browser entry @mcp-ubuntu-latest
❌ [chrome] › mcp/cli-json.spec.ts:75 › open returns envelope with session, pid and snapshot file @mcp-windows-latest
❌ [chrome] › mcp/cli-json.spec.ts:103 › goto returns snapshot file envelope @mcp-windows-latest
❌ [chromium] › mcp/cli-json.spec.ts:75 › open returns envelope with session, pid and snapshot file @mcp-windows-latest
❌ [chromium] › mcp/cli-json.spec.ts:84 › list after open returns one browser entry @mcp-windows-latest
❌ [chromium] › mcp/cli-json.spec.ts:103 › goto returns snapshot file envelope @mcp-windows-latest
❌ [firefox] › mcp/cli-json.spec.ts:75 › open returns envelope with session, pid and snapshot file @mcp-windows-latest
❌ [firefox] › mcp/cli-json.spec.ts:103 › goto returns snapshot file envelope @mcp-windows-latest
❌ [chromium] › mcp/cli-json.spec.ts:84 › list after open returns one browser entry @mcp-macos-latest
❌ [webkit] › mcp/cli-json.spec.ts:75 › open returns envelope with session, pid and snapshot file @mcp-windows-latest
❌ [webkit] › mcp/cli-json.spec.ts:103 › goto returns snapshot file envelope @mcp-windows-latest
❌ [msedge] › mcp/cli-json.spec.ts:75 › open returns envelope with session, pid and snapshot file @mcp-windows-latest
❌ [msedge] › mcp/cli-json.spec.ts:103 › goto returns snapshot file envelope @mcp-windows-latest

6382 passed, 976 skipped


Merge workflow run.

const timeout = timeouts[Math.min(timeoutIndex++, timeouts.length - 1)];
let timeout = timeouts[Math.min(timeoutIndex++, timeouts.length - 1)];
if (timeout && progress.deadline) {
// Clamp the sleep to the remaining budget (minus a small margin for the
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100ms is arbitrary here, it can take any amount of time, so we are trading a 1000ms race for 100ms race. not quite sure that is what we want, but I don't have a good idea on it either. as an idea, you could measure the action and give it twice its budget?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can try to run the "one-shot" logic at the end of the timeout, instead of at the start? Not sure how that will look like, but worth a try.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't like that as we could fall far behind the deadline, but if the operation is long it's not much different than starting 100ms before the deadline, we can try that.

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.

[Bug]: Expect assertions with escalating retry intervals skip final check before deadline, wasting up to 1000ms of timeout budget

3 participants