Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle timeout when waiting for page readiness #30

Merged
merged 1 commit into from
Nov 30, 2023

Conversation

jugglinmike
Copy link
Contributor

Prior to this commit, if the Promise stored in the binding named loaded rejected while the WebDriver "wait" command was being evaluated, that rejection would trigger a Node.js global "unhandled rejection" error and cause the process to crash.

Track all Promise values so that a rejection in any of them at any time is handled by the caller. Recognize when the expected "load" event has already occurred and stop waiting immediately.


@gnarf I've had a change of heart from my comment yesterday. Since we are preparing to deploy this for the very first time, there's relatively little risk in changing old code. Now seems like a good opportunity to challenge assumptions because everyone involved expects the initial release to be unstable.

To that end, I've simplified this logic to wait for "document readiness" and only then begin waiting for the presence of the "setup" button. That's involved addressing the previously-overlooked race condition with the "ready" event (one which you and I haven't discussed); now, this new version of the code recognizes when the event occurs before the script injection via WebDriver.

Beyond improving maintainability and reducing the risk of further design flaws, this change has the potential to significantly reduce the amount of time necessary to run the tests (since the harness will no longer pause for five seconds when it missed the "load" event). Another benefit is the surfacing of legitimate errors (because the harness no longer ignores all "execute script" timeouts unilaterally).

The risk to this change is that it exposes a latent race condition. In other words, it's possible that the overlong timeouts before were coincidentally delaying the test execution beyond some other, as-yet-unidentified pre-condition. To guard against that, I'm running some tests to see if the results still look reasonable; would you mind doing the same? (Such informal evidence would not normally convince me, but again, because we're deploying a new system, I'm a little more willing to experiment for the sake of more deterministic code.)

Prior to this commit, if the Promise stored in the binding named
`loaded` rejected while the WebDriver "wait" command was being
evaluated, that rejection would trigger a Node.js global "unhandled
rejection" error and cause the process to crash.

Track all Promise values so that a rejection in any of them at any time
is handled by the caller. Recognize when the expected "load" event has
already occurred and stop waiting immediately.
@jugglinmike jugglinmike requested a review from gnarf November 29, 2023 21:00
Copy link
Contributor

@gnarf gnarf left a comment

Choose a reason for hiding this comment

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

Code looks good.

Starting some local testing, can already tell that the whole process feels much faster (must've always been timing out before as you said)

@gnarf
Copy link
Contributor

gnarf commented Nov 29, 2023

Tested the following so far with no errors/extra weird results

  • checkbox-tri-state
  • breadcrumbs
  • color-slider
  • form
  • alert

@jugglinmike
Copy link
Contributor Author

Right on! Thanks, @gnarf!

@jugglinmike jugglinmike merged commit 891ddbd into w3c:main Nov 30, 2023
6 checks passed
@jugglinmike jugglinmike deleted the fix-loading-bug-2 branch November 30, 2023 01:01
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