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

fix: stop subscription race condition error on debug page #27134

Merged
merged 9 commits into from Jun 28, 2023

Conversation

warrensplayer
Copy link
Contributor

@warrensplayer warrensplayer commented Jun 26, 2023

Additional details

Summary
A race condition between two different subscriptions used on the Debug page was causing a GraphQL error to be shown to the user when viewing a running Cypress Cloud build. The error would have no effect on the results being shown on the page and resolve itself after the next polling cycle for the running build.

Issue
The error occurred because the RevelentRunSpecsDataSource allows the front end to pass different GraphQL fields to be returned for the relevantRunSpecChange subscription on the CloudRun type. These fields get combined into one query that is sent to Cypress Cloud.

The race condition was occurring when the following steps occurred:

  • The subscription in DebugTestingProgress would run first and kick off the underlying poller in the data source and cause the first cloud query to start.
  • When awaiting the return of this query, the subscription in useDebugRunSummary would be mounted and register itself to watch for emitted results. The second subscription asked for the createdAt field which is a non-nullable field as defined in the GraphQL type. The first subscription did not ask for this field.
  • When the initial query returned, the value would be emitted and checked by the filter function which would only check to see if the run ids matched.
  • Urql would try to resolve those initial values for the second subscription, it would show the error in the before video below due to the missing createdAt.
  • Finally, the second polling cycle would run and now have both GraphQLResolveInfo objects, it would generate a GraphQL query that correctly satisfy both subscriptions.

Solution
The fix was to add an additional check to the filter function to also validate that the object being emitted had the fields asked for that particular subscription. The trade off for this solution is that the second subscription will not have accurate results for one additional polling cycle (currently 15 seconds).

Before

Screen.Recording.2023-06-26.at.9.47.26.AM.mov

After

after_trimmed.mov

Steps to test

  • Visit debug page for a RUNNING build.
  • No GraphQL error should be shown and page should update as expected

How has the user experience changed?

No error toast is shown when viewing a running build on the Debug page.

PR Tasks

@warrensplayer warrensplayer marked this pull request as ready for review June 26, 2023 16:12
@warrensplayer warrensplayer requested a review from a team June 26, 2023 16:12
@cypress
Copy link

cypress bot commented Jun 26, 2023

15 flaky tests on run #48325 ↗︎

0 10227 1026 0 Flakiness 15

Details:

Fix linting for changelog
Project: cypress Commit: 57df2b0de7
Status: Passed Duration: 15:09 💡
Started: Jun 28, 2023 12:44 PM Ended: Jun 28, 2023 12:59 PM
Flakiness  create-from-component.cy.ts • 1 flaky test • app-e2e

View Output Video

Test Artifacts
... > runs generated spec Output Screenshots Video
Flakiness  specs_list_latest_runs.cy.ts • 1 flaky test • app-e2e

View Output Video

Test Artifacts
App/Cloud Integration - Latest runs and Average duration > when no runs are recorded > shows placeholders for all visible specs Output Screenshots Video
Flakiness  cypress-origin-communicator.cy.ts • 1 flaky test • app-e2e

View Output Video

Test Artifacts
Cypress In Cypress Origin Communicator > cy.origin passivity with app interactions > passes upon test reload mid test execution Output Screenshots Video
Flakiness  subscriptions/configChange-subscription.cy.ts • 1 flaky test • app-e2e

View Output Video

Test Artifacts
configChange subscription > on config page > responds to configChange event when viewport is changed Output Screenshots Video
Flakiness  e2e/origin/cookie_login.cy.ts • 1 flaky test • 5x-driver-electron

View Output Video

Test Artifacts
... > past Max-Age, before Expires -> not logged in Output Video

The first 5 flaky specs are shown, see all 10 specs in Cypress Cloud.

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

Copy link
Contributor

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

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

Great, looks good - thanks for adding a test. I think I'd seen this before, but thought it was due to my local repo getting messed up when I changed branches, I should have looked into it more at that point.

Are you just debugging this by kicking off runs and using debug and trying different edge cases? I imagine this was a bit tricky to track down and debug.

Re: the code, I'm not sure the test description is ideal - there's a lot of complexity in the test, it might not be immediately obvious why (unless the user follows the git blame -- that might be enough, probably more informative than any test description can be).

Test description aside, this looks good.

@lmiller1990 lmiller1990 requested a review from a team June 27, 2023 02:55
Copy link
Contributor

@astone123 astone123 left a comment

Choose a reason for hiding this comment

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

This worked for me 👍🏻 thanks for fixing this!

@warrensplayer warrensplayer merged commit 15efb64 into develop Jun 28, 2023
76 of 78 checks passed
@warrensplayer warrensplayer deleted the stokes/debug_running_race_condition branch June 28, 2023 13:00
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jul 6, 2023

Released in 12.17.0.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jul 6, 2023
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.

None yet

3 participants