Skip to content

Fix late webview completion race - #212

Merged
e271828- merged 3 commits into
masterfrom
fix/toktest
Mar 25, 2026
Merged

Fix late webview completion race#212
e271828- merged 3 commits into
masterfrom
fix/toktest

Conversation

@e271828-

@e271828- e271828- commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Summary

This fixes the late-completion race behind the flaky HCaptchaWebViewManager__Tests.test__Configure_Web_View failure seen in GitHub Actions job 67922018521, while keeping HCaptcha__Bench.testBenchVerify measuring webview startup plus verification.

Reference:

Root Cause

HCaptchaWebViewManager kept the active validation completion alive after delivering a terminal result.

That allowed later WKNavigationDelegate callbacks, especially webViewWebContentProcessDidTerminate, to re-enter the same completion path with an error result after success had already been delivered.

The earlier branch version tried to hide that race by preloading the benchmark before measureMetrics, but that changed what testBenchVerify measures. We do not want that benchmark warmed up ahead of time.

What Changed

  • Terminal result delivery now goes through complete(...), which clears the stored completion before invoking it.
  • validate(on: nil) now uses the same terminal completion path for .failedSetup.
  • stop() clears any pending completion so post-stop callbacks cannot leak through.
  • The benchmark warmup added in this branch was removed, so testBenchVerify still includes webview startup time.
  • The regression test test__Validate__Ignores_Late_Termination_After_Token remains to cover the late-termination case directly.

Validation

Ran locally:

  • xcodebuild test -workspace Example/HCaptcha.xcworkspace -scheme HCaptcha_Tests -destination 'platform=iOS Simulator,id=AD95999C-D8DE-4206-848B-AF7EC34B7EA9' -only-testing 'HCaptcha_Tests/HCaptchaWebViewManager__Tests/test__Validate__Ignores_Late_Termination_After_Token' -only-testing 'HCaptcha_Tests/HCaptchaWebViewManager__Tests/test__Configure_Web_View' -only-testing 'HCaptcha_Tests/HCaptchaWebViewManager__Tests/test__Stop'
  • xcodebuild test -workspace Example/HCaptcha.xcworkspace -scheme HCaptcha_Tests -destination 'platform=iOS Simulator,id=AD95999C-D8DE-4206-848B-AF7EC34B7EA9' -only-testing 'HCaptcha_Tests/HCaptcha__Bench/testBenchVerify'

Both passed.

@github-actions

Copy link
Copy Markdown

Cocoapods size report:

OLD: 146409 bytes
NEW: 163393 bytes

DIFF: 16984 bytes

@e271828-
e271828- requested a review from CAMOBAP March 20, 2026 17:11
CAMOBAP
CAMOBAP previously approved these changes Mar 21, 2026
@e271828-
e271828- marked this pull request as draft March 22, 2026 14:22
@e271828-

Copy link
Copy Markdown
Contributor Author

draft, as we may want to keep recording including the initial load cost.

@e271828- e271828- changed the title Fix flaky benchmark completion handling Fix late webview completion race Mar 23, 2026
@e271828-
e271828- marked this pull request as ready for review March 25, 2026 10:28
@e271828-
e271828- merged commit 526f477 into master Mar 25, 2026
10 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.

2 participants