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

perf: fix performance issue for service workers that don't handle requests #28900

Merged
merged 43 commits into from
Mar 5, 2024

Conversation

mschile
Copy link
Contributor

@mschile mschile commented Feb 8, 2024

Additional details

We fixed an issue in 13.6.3 involving service workers to ensure that we could capture those requests properly for Test Replay and intercepts. Currently, when a service worker is registered, we incorrectly assumed that all requests would be handled by the service worker. Thus, if a request was not handled, the proxy would fail to correlate causing a timeout.

In order to resolve the issue, we are now overriding the fetch event and respondWith methods within the service worker to determine if respondWith was called.

  • Added new MaybeInjectServiceWorker response middleware that injects code into the top of the service worker to overwrite the addEventListener, removeEventListener, onfetch, and respondWith functions.
    • the addEventListener and onfetch functions will now determine if respondWith was called and call the CDP binding to inform the ServiceWorkerManager whether or not the service worker handled the request.
    • the removeEventListener function is needed to appropriately remove the added listeners
  • Added a new CDP binding __cypressServiceWorkerClientEvent that is used to communicate the events from the client
  • The ServiceWorkerManager will now wait until it is notified by the client if the service worker is handling the request before communicating to the proxy to ignore the browser's pre-request

Steps to test

  • Run a test on a site that uses a service worker but does not handle all requests and verify no correlation timeouts are observed.

How has the user experience changed?

Unhandled service worker requests will no longer hit the 2 second correlation timeout.

PR Tasks

Copy link

cypress bot commented Feb 8, 2024

28 failed and 2 flaky tests on run #54371 ↗︎

28 691 42 0 Flakiness 2

Details:

Merge branch 'develop' into mschile/service_worker
Project: cypress Commit: bba9f386b0
Status: Failed Duration: 16:08 💡
Started: Mar 5, 2024 5:16 PM Ended: Mar 5, 2024 5:32 PM
Failed  cypress\e2e\runner\reporter.hooks.cy.ts • 1 failed test • app-e2e

View Output

Test Artifacts
hooks > creates open in IDE button Test Replay Screenshots
Failed  cypress\e2e\runner\reporter-ct-vite.errors.cy.ts • 14 failed tests • app-e2e

View Output

Test Artifacts
Vite - errors ui > assertion failures Test Replay Screenshots
Vite - errors ui > assertion failures - no preferred IDE Test Replay Screenshots
Vite - errors ui > hooks Test Replay Screenshots
Vite - errors ui > cy.then Test Replay Screenshots
Vite - errors ui > cy.should Test Replay Screenshots
Vite - errors ui > cy.each Test Replay Screenshots
Vite - errors ui > cy.spread Test Replay Screenshots
Vite - errors ui > cy.within Test Replay Screenshots
Vite - errors ui > cy.wrap Test Replay Screenshots
Vite - errors ui > cy.intercept Test Replay Screenshots
The first 10 failed tests are shown, see all 14 tests in Cypress Cloud.
Failed  cypress\e2e\runner\reporter.command_errors.cy.ts • 13 failed tests • app-e2e

View Output

Test Artifacts
errors ui > assertion failures Test Replay Screenshots
errors ui > assertion failures - no preferred IDE Test Replay Screenshots
errors ui > cy.then Test Replay Screenshots
errors ui > cy.should Test Replay Screenshots
errors ui > cy.each Test Replay Screenshots
errors ui > cy.spread Test Replay Screenshots
errors ui > cy.within Test Replay Screenshots
errors ui > cy.wrap Test Replay Screenshots
errors ui > cy.visit Test Replay Screenshots
errors ui > cy.intercept Test Replay Screenshots
The first 10 failed tests are shown, see all 13 tests in Cypress Cloud.
Failed  cypress\e2e\debug.cy.ts • 0 failed tests • app-e2e

View Output

Test Artifacts
Failed  cypress\e2e\specs_list_component.cy.ts • 0 failed tests • app-e2e

View Output

Test Artifacts

The first 5 failed specs are shown, see all 19 specs in Cypress Cloud.

Flakiness  cypress\e2e\specs_list_latest_runs.cy.ts • 1 flaky test • app-e2e

View Output

Test Artifacts
App/Cloud Integration - Latest runs and Average duration > when no runs are recorded > shows placeholders for all visible specs Test Replay Screenshots
Flakiness  cypress\e2e\migration.cy.ts • 1 flaky test • launchpad-e2e

View Output

Test Artifacts
Full migration flow for each project > migration-e2e-component-default-test-files > skips the file renaming Test Replay Screenshots

Review all test suite changes for PR #28900 ↗︎

@mschile mschile requested a review from ryanthemanuel February 9, 2024 16:30
MikeMcC399

This comment was marked as resolved.

Co-authored-by: Mike McCready <66998419+MikeMcC399@users.noreply.github.com>
MikeMcC399

This comment was marked as outdated.

Copy link
Contributor

@MikeMcC399 MikeMcC399 left a comment

Choose a reason for hiding this comment

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

Apparently a "Comment" doesn't override "Request changes", so I'm "Approving" to avoid a dangling "Request changes" status.
This is only with regard to the changelog entry though.

@mschile mschile requested a review from cacieprins February 28, 2024 16:57
Copy link
Contributor

@cacieprins cacieprins left a comment

Choose a reason for hiding this comment

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

Mostly typescript & DRY quibbles, otherwise lgtm!

@mschile mschile requested a review from cacieprins March 4, 2024 22:18
@mschile mschile merged commit a29eae9 into develop Mar 5, 2024
109 of 116 checks passed
@mschile mschile deleted the mschile/service_worker branch March 5, 2024 18:25
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 13, 2024

Released in 13.7.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v13.7.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Mar 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Performance regression in 13.6.3 when using service workers that don't proxy every request
4 participants