-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 flaky Nav block user permissions e2e test #38025
Fix flaky Nav block user permissions e2e test #38025
Conversation
Size Change: 0 B Total Size: 1.13 MB ℹ️ View Unchanged
|
@talldan Could you do me a favour and (assuming you agree with the premise of this PR) restart the tests for runs 4 & 5, checking off s required in the PR desc. If all good then I think we are ok to merge this one. |
// Creation of the contributor user **MUST** be at the top level describe block | ||
// otherwise this test will become unstable. This action only happens once | ||
// so there is no huge performance hit. | ||
contributorPassword = await createUser( contributorUsername, { | ||
role: 'contributor', | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there's a bug in the e2e helpers so that switching to a newly created user is unreliable? Otherwise, I can't think of any other reason why this has to be at the root level.
loginUser
doesn't check if the submission is successful, it only tries to fill out the login form and press the login button. Perhaps we can add an assertion in the helper and/or throw a meaningful error message as to why it fails.
The same goes createUser
. It doesn't check if the action is successful either. The password it returns is auto-generated before the submission, so checking its existence isn't enough either.
I'm guessing maybe one of these helpers failed at some point and we didn't catch it. The reason it's less unreliable in top-level describe block is still unknown though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd definitely be good to try to understand the root cause, as otherwise it'll be difficult to use this utility in other tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a good opportunity to rewrite these utils with rest
or something similar too 🙈 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't realise it wasn't already using REST. Yeah, I definitely think that'd be a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Are we able to ship this fix now though so we have test coverage and then circle back to making it REST?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, absolutely. I have a draft PR opened at #38060 which might be helpful for that matter and I'll work on it next.
@@ -211,6 +211,18 @@ async function getNavigationMenuRawContent() { | |||
// Disable reason - these tests are to be re-written. | |||
// eslint-disable-next-line jest/no-disabled-tests | |||
describe( 'Navigation', () => { | |||
const contributorUsername = 'contributoruser'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should make the username unique by adding some randomness, as one of the reasons WordPress would prevent creation of a user is a duplicate username, and that might happen if clean up of this test fails, or possibly another test using the same username.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added randomness using lodash. Does that work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be slightly over-engineered. I'd imagine a better solution would be having a proper error message if that happens. We are already running our tests in-band, so such things shouldn't happen. If they happen, it might be because our test cases aren't being correctly cleaned up, and we should fix them. But it's not that it's an anti-pattern or anything like that, I don't mind landing this 😅 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, it shouldn't happen, but if it did I feel like it would still be really obscure and hard to track down. Better error messages would be good though.
I don't think _.uniqueId
would do the job anyway, as that's just an incrementing integer. Another test in a new process would generate the same integer.
I notice this is failing quite a lot, so I've skipped the test for now until this is ready to merge - #38099 I'm happy to go ahead with this change as a temporary step to stabilise the test, but that first comment from @kevin940726 about the |
Acts a safeguard against duplicate users.
afeb5fd
to
a60a47e
Compare
Nice one. Thanks.
I think @kevin940726 might be mistaken. It's already in the Also I rebased the branch and also added randomness to the username. Let me know if this can merge or if there's more that needs to happen. |
Just re-running this a few times to ensure it's still stable. @talldan when you come online if this is still ✅ feel free to merge. |
Description
The user permissions test for the Nav block have been flaky recently. I wondered why this was because when I committed they weren't - I ran several test runs on CI to confirm that fact.
After some digging I noticed that a92586c moved the creation of the contributor user to be local to the
describe
block where the permissions tests are performed. However, when @ockham and I originally debugged this test (when it was created) we ascertained that the contributor user creation had to happen at the top/root leveldescribe
block otherwise the test was unstable. We don't know why that is but it is probably a quirk of Puppetter.This PR moves the user creation back to the root level
describe
in the hope that will make the test stable again.Closes #37604
How has this been tested?
Run the CI e2e tests and make sure that the x2 tests below do not fail:
shows a warning if user does not have permission to edit or update navigation menus
shows a warning if user does not have permission to create navigation menus
We should run the CI on this PR 5 times to be reasonably sure this fix does actually produce a more stable test. Please check off below when you see a valid test run:
Screenshots
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).