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

Admin menu: Avoid usage of pseudorandom numbers in tests #24224

Merged
merged 4 commits into from
May 3, 2022

Conversation

mmtr
Copy link
Member

@mmtr mmtr commented May 3, 2022

Changes proposed in this Pull Request:

WordPress 6.0 will change how menus are positioned when there is a collision between items that are supposed to be in the same position: https://core.trac.wordpress.org/ticket/40927

In such cases, WordPress generates a pseudorandom number to be used as the position key in order to guarantee there are no duplicated keys. However, the logic for generating that number has changed in WordPress 6.0.

We had a couple of tests that relied on such number, so to avoid failures in these tests in WordPress 6.0 this PR adapts their implementation to don't rely in it.

Originally reported by @david-binda in D79094-code.

Jetpack product discussion

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

Make sure tests pass.

@mmtr mmtr added the [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. label May 3, 2022
@mmtr mmtr requested a review from david-binda May 3, 2022 12:02
@mmtr mmtr self-assigned this May 3, 2022
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello mmtr! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer and confirm D79957-code works as expected before merging this PR. Once this PR is merged, please commit the changes to WP.com. Thank you!
This revision will be updated with each commit to this PR

@github-actions github-actions bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Feature] Masterbar WordPress.com Toolbar and Dashboard customizations Unit Tests labels May 3, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 3, 2022

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: June 7, 2022.
  • Scheduled code freeze: May 30, 2022.

@mmtr mmtr added [Status] In Progress and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels May 3, 2022
@mmtr mmtr added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] In Progress labels May 3, 2022
@mmtr mmtr added this to the jetpack/11.0 milestone May 3, 2022
@mmtr mmtr requested a review from obenland May 3, 2022 13:45
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

I looked at that issue in #24083, and took a different approach there. I suppose your approach is simpler though :)

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels May 3, 2022
@kraftbj kraftbj merged commit d0c2098 into master May 3, 2022
@kraftbj kraftbj deleted the fix/admin-menu-tests-wp6 branch May 3, 2022 13:54
@github-actions
Copy link
Contributor

github-actions bot commented May 3, 2022

Great news! One last step: head over to your WordPress.com diff, D79957-code, and deploy it.
Once you've done so, come back to this PR and add a comment with your changeset ID.

Thank you!

@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label May 3, 2022
@kraftbj
Copy link
Contributor

kraftbj commented May 3, 2022

r244847-wpcom

@anomiex
Copy link
Contributor

anomiex commented May 3, 2022

In such cases, WordPress generates a pseudorandom number to be used as the position key in order to guarantee there are no duplicated keys.

It's not at all pseudorandom. It hashes the menu title and slug.

@mmtr
Copy link
Member Author

mmtr commented May 3, 2022

It's not at all pseudorandom. It hashes the menu title and slug.

Right, I took that from what was said in https://core.trac.wordpress.org/ticket/40927#comment:40, but it's not pseudoramdom at all, just a hash.

Anyway, I don't think we should have logic/tests that expects a certain menu position hash given that WordPress doesn't expose it in any way and should be considered as unreliable/indeterminate.

@david-binda
Copy link
Contributor

Thank you all for working on this! 🙇

@jeherve jeherve modified the milestones: jetpack/11.0, jetpack/10.9.1 May 19, 2022
jeherve pushed a commit that referenced this pull request May 19, 2022
* Admin menu: Avoid usage of pseudorandom numbers in tests
@jeherve
Copy link
Member

jeherve commented May 19, 2022

Cherry-picked to jetpack/branch-10.9 in a283d48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Masterbar WordPress.com Toolbar and Dashboard customizations [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ Touches WP.com Files Unit Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants