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: [M3-8602] - Fix plan-selection.spec.ts test failures on retries #10976

Conversation

jdamore-linode
Copy link
Contributor

@jdamore-linode jdamore-linode commented Sep 19, 2024

Description 📝

This fixes a minor test flaw in the plan-selection.spec.ts spec where mocks are getting set up in before hooks instead of beforeEach hooks. This prevents mocks from being applied on test retries (because mocks get cleared between tests, but before hooks only get called once), causing retries in this spec to be guaranteed to fail.

Changes 🔄

  • Replace before hooks with beforeEach in plan-selection.spec.ts to ensure mocks get applied on test retries

Target release date 🗓️

N/A

How to test 🧪

Reproduction steps

In develop (edit: the issue causing the initial failure has been fixed, so reproducing this is now pretty difficult), build Cloud via yarn && yarn build && yarn start:manager:ci and then:

repeat 5 yarn cy:run -s "cypress/e2e/core/linodes/plan-selection.spec.ts

Observe flakiness (in my case, the spec failed 4 out of 5 times).

Verification steps

Check out this branch, build Cloud via yarn && yarn build && yarn start:manager:ci and then:

repeat 5 yarn cy:run -s "cypress/e2e/core/linodes/plan-selection.spec.ts

Observe the test passes each time. I was able to run the test 50 times on repeat without failures.

We can also rely on CI to some extent -- this issue theoretically impacts all of our Autocompletes, so any test failures involving an Autocomplete (including region selects, etc.) should receive extra scrutiny.

Manual verification

Some extra attention should be given to the "Phone Verification" field at /profile/auth since it's the only Autocomplete I'm aware of that takes advantage of the recent changes to the PopperComponent prop, so it may be at more risk of being broken by these changes than other Autocompletes.

As an Author I have considered 🤔

Check all that apply

  • 👀 Doing a self review
  • ❔ Our contribution guidelines
  • 🤏 Splitting feature into small PRs
  • ➕ Adding a changeset
    • Pushed a changeset for the test fix since that's been a flaw all along, but don't think a changeset is necessary for the Autocomplete change since 10780 hasn't been released yet. Thoughts?
  • 🧪 Providing/Improving test coverage
  • 🔐 Removing all sensitive information from the code and PR description
  • 🚩 Using a feature flag to protect the release
  • 👣 Providing comprehensive reproduction steps
  • 📑 Providing or updating our documentation
  • 🕛 Scheduling a pair reviewing session
  • 📱 Providing mobile support
  • ♿ Providing accessibility support

@jdamore-linode jdamore-linode self-assigned this Sep 19, 2024
@jdamore-linode jdamore-linode requested a review from a team as a code owner September 19, 2024 20:24
@jdamore-linode jdamore-linode requested review from bnussman-akamai and coliu-akamai and removed request for a team September 19, 2024 20:24
Comment on lines 112 to 119
/* Memoize popper callback to prevent unnecessary popper re-rendering. */
const customPopper = useCallback(
(props: PopperProps) => {
return <CustomPopper {...props} sx={sxPopperComponent} />;
},
[sxPopperComponent]
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a suggestion I saw on a StackOverflow thread, but hoping that somebody with more React expertise than me could take a look at this and double check that this is a sensible solution.

It seems to make the tests very happy, and I didn't notice any regressions during my manual testing, but I'd be lying if I said I fully understand the implications of wrapping this in useCallback.

Copy link
Member

Choose a reason for hiding this comment

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

Hey Joe! Take a look at #10978. Do you think this could be a better way to approach it and would it fix the unexpected re-render / arrow function issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @bnussman-akamai!

Commented on your PR, but I think your solution is hands down better: it fixes the test failures and I'm guessing it's a lot more idiomatic / in line with the way we normally do things. Happy to either integrate your implementation into this PR or let you take the reins with #10978!

Copy link
Contributor

Choose a reason for hiding this comment

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

@jdamore-linode Do you happen to have the link to the StackOverflow thread? I'm curious why useCallback was used instead of useMemo and would be interested in reading more into it. Anyway, @bnussman-akamai provided a very good alternative and I see it's been merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@carrillo-erik not on hand, no -- I could try to find it, but I was already a bit doubtful about useCallback as a solution for this, and I think Bank's solution demonstrates that it wasn't really necessary in the first place, so I don't think I'd consider the answer in that thread as authoritative in this case

@jdamore-linode jdamore-linode changed the title fix: [M3-8617] - Fix Autocomplete popper re-rendering causing test failures fix: [M3-8602, M3-8617] - Fix Autocomplete popper re-rendering causing test failures Sep 19, 2024
@jdamore-linode jdamore-linode requested a review from a team as a code owner September 19, 2024 20:35
@jdamore-linode jdamore-linode requested review from AzureLatte and removed request for a team September 19, 2024 20:35
@@ -124,7 +124,7 @@ const notices = {

authenticate();
describe('displays linode plans panel based on availability', () => {
before(() => {
beforeEach(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using before here instead of beforeEach causes the mocks not to get applied on re-attempts which leads to failures.

The initial failure is caused by the cy.click() issue, but plan-selection.spec.ts failures are overrepresented in CI due to the re-attempts being guaranteed to fail.

Copy link

github-actions bot commented Sep 19, 2024

Coverage Report:
Base Coverage: 87.13%
Current Coverage: 87.13%

@jdamore-linode jdamore-linode changed the title fix: [M3-8602, M3-8617] - Fix Autocomplete popper re-rendering causing test failures fix: [M3-8602] - Fix plan-selection.spec.ts test failures on retries Sep 20, 2024
Copy link
Contributor

@carrillo-erik carrillo-erik left a comment

Choose a reason for hiding this comment

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

Approved based on our conversation with the understanding that some minor changes will be implemented.

Copy link
Contributor

@coliu-akamai coliu-akamai left a comment

Choose a reason for hiding this comment

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

thanks Joe!
✅ confirmed tests passed repeatedly
✅ manually tested the phone # autocomplete on /profile/auth + ran sms-verication.spec as well to confirm it passed

@jdamore-linode jdamore-linode merged commit 4a418fa into linode:develop Sep 20, 2024
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants