Skip to content

Cancel leaked WKWebView navigations in test simulator#229

Open
olivaresf wants to merge 1 commit intofernando/structured-errorsfrom
fernando/fix-test-simulator-leak
Open

Cancel leaked WKWebView navigations in test simulator#229
olivaresf wants to merge 1 commit intofernando/structured-errorsfrom
fernando/fix-test-simulator-leak

Conversation

@olivaresf
Copy link
Member

@olivaresf olivaresf commented Feb 12, 2026

Summary

  • WebViewNavigationSimulator.decidePolicyFor always called decisionHandler(.allow), which let WKWebView actually navigate to https://example.com over the real network after capturing the WKNavigationAction. This blocked WebKit's shared WKProcessPool and stalled subsequent tests for 12+ minutes in CI.
  • Now calls .cancel once the WKNavigationAction is captured (which is all the tests need), and .allow only for intermediate navigations that must complete (e.g., the initial loadHTMLString page load)
  • Adds stopLoading() cleanup in tearDown as a safety net

Before & after (local run, 208 tests on main)

Test Before After
test_handling_link_activated_... 759s 0.77s
BridgeComponentAsyncAPITests.test_didReceiveCachesTheMessage 137s 7.2s
BridgeComponentAsyncAPITests.test_replyToMessageNotReceived... 18s 0.66s
Total suite ~1018s ~52s

Test plan

  • Full test suite passes locally (208 tests, 0 failures)
  • CI passes on this PR

🤖 Generated with Claude Code

WebViewNavigationSimulator always called decisionHandler(.allow), which
let WKWebView actually navigate to https://example.com over the network.
This blocked the shared WKProcessPool and stalled subsequent tests for
12+ minutes in CI.

Now the simulator calls .cancel once it has captured the WKNavigationAction
(which is all the tests need), and .allow only for intermediate navigations
that must complete (e.g., the initial loadHTMLString page load). Also adds
stopLoading() cleanup in tearDown as a safety net.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@joemasilotti
Copy link
Member

Yes!! This has been bugging me for so long. Glad to see it finally getting addressed. Nice work @olivaresf!

@olivaresf olivaresf changed the base branch from main to fernando/structured-errors February 13, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants