Skip to content

fix(mcp): propagate abort signal to stop test execution#40582

Merged
pavelfeldman merged 3 commits intomicrosoft:mainfrom
mxschmitt:mxschmitt/fix-38937
May 6, 2026
Merged

fix(mcp): propagate abort signal to stop test execution#40582
pavelfeldman merged 3 commits intomicrosoft:mainfrom
mxschmitt:mxschmitt/fix-38937

Conversation

@mxschmitt
Copy link
Copy Markdown
Contributor

Summary

  • Propagate AbortSignal from MCP SDK through TestServerBackend → tool handlers → TestContext
  • Serialize test operations via a promise queue to prevent race conditions when abort is followed by an immediate new run
  • On abort, call runner.stopTests() and run global teardown before releasing the queue

Fixes #38937


private _enqueue<T>(fn: () => Promise<T>): Promise<T> {
const result = this._testOpQueue.then(fn);
this._testOpQueue = result.then(() => {}, () => {});
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.

This will catch all the errors silently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed to match the TestRunner.runTests() pattern — single chain with await this._queue, no separate error handler needed since _runTestsImpl has its own try/catch and never rejects.

@mxschmitt mxschmitt force-pushed the mxschmitt/fix-38937 branch from 46b0543 to 1a380e8 Compare May 5, 2026 18:26
Use single-chain await style matching TestRunner.runTests(),
avoiding the empty error handler that looked like it was
silently swallowing errors.
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@mxschmitt
Copy link
Copy Markdown
Contributor Author

Windows CI failures are pre-existing and unrelated to this PR — dashboard.spec.ts annotate tests are also failing on main: https://github.com/microsoft/playwright/actions/runs/25396744541/job/74485425551

Comment thread packages/playwright/src/mcp/test/testContext.ts Outdated
Comment thread packages/playwright/src/mcp/test/testContext.ts Outdated
- Simplify _enqueue to match TestRunner queue pattern
- Extract signalToPromise utility to @isomorphic/manualPromise
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Test results for "MCP"

12 failed
❌ [firefox] › mcp/test-run.spec.ts:126 › test_run should stop when aborted @mcp-windows-latest-firefox
❌ [firefox] › mcp/tracing.spec.ts:21 › check that trace is saved with browser_start_tracing @mcp-windows-latest-firefox
❌ [msedge] › mcp/test-run.spec.ts:126 › test_run should stop when aborted @mcp-windows-latest-msedge
❌ [webkit] › mcp/config.ini.spec.ts:57 › ini config sets browser launch options @mcp-windows-latest-webkit
❌ [webkit] › mcp/dashboard.spec.ts:207 › should enter annotate mode on fresh dashboard.tsx mount with -s --annotate @mcp-windows-latest-webkit
❌ [webkit] › mcp/dashboard.spec.ts:231 › should annotate via direct browser_annotate MCP call @mcp-windows-latest-webkit
❌ [webkit] › mcp/dashboard.spec.ts:264 › should annotate when context has no fixed viewport @mcp-windows-latest-webkit
❌ [webkit] › mcp/dashboard.spec.ts:301 › should cancel browser_annotate when the MCP request is aborted @mcp-windows-latest-webkit
❌ [webkit] › mcp/dashboard.spec.ts:332 › should cancel browser_annotate when the MCP client disconnects @mcp-windows-latest-webkit
❌ [webkit] › mcp/dashboard.spec.ts:361 › should switch screencast to -s session on show --annotate @mcp-windows-latest-webkit
❌ [webkit] › mcp/dashboard.spec.ts:410 › should disengage annotate mode when --annotate client disconnects @mcp-windows-latest-webkit
❌ [webkit] › mcp/dashboard.spec.ts:499 › save recording streams WebM bytes to the chosen file @mcp-windows-latest-webkit

6944 passed, 1052 skipped


Merge workflow run.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Test results for "tests 1"

1 failed
❌ [firefox-page] › page/page-emulate-media.spec.ts:196 › should report hover and fine pointer for desktop @firefox-ubuntu-22.04-node20

41661 passed, 851 skipped


Merge workflow run.

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]: MCP test_run tool doesn't stop test execution when aborted

2 participants