-
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
chore: Isolate e2e tests and reset them for each run #8041
chore: Isolate e2e tests and reset them for each run #8041
Conversation
. "$(dirname "$0")/includes.sh" | ||
|
||
# Set up WordPress site used for end-to-end (e2e) tests. | ||
. "$(dirname "$0")/install-wordpress.sh" --e2e_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.
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.
A reinstall is pretty quick, and it guarantees you're getting a fresh state.
docker-compose.yml
Outdated
- ./test/e2e/test-plugins:/var/www/html/wp-content/plugins/gutenberg-test-plugins | ||
- ./test/e2e/test-mu-plugins:/var/www/html/wp-content/mu-plugins | ||
|
||
mysql_e2e_test: |
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 seems like overkill, but I couldn't find a(n easy) way to create two separate databases we could use in the same container from different WordPress images. I'd like to just have a wordpress
and wordpress_e2e_test
database in the same container, so if we can easily do that, let me know.
|
||
// The Jest timeout is increased because these tests are a bit slow | ||
jest.setTimeout( 100000 ); | ||
jest.setTimeout( PUPPETEER_TIMEOUT || 100000 ); |
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 seemed a handy thing to have so I added it, but if it's no good let me know.
test/e2e/support/bootstrap.js
Outdated
|
||
await visitAdmin( 'edit.php' ); | ||
|
||
const bulkSelector = await page.$( '#bulk-action-selector-top' ); |
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'm thinking I should add some comments to this explaining what it does, but the gist is that it opens the admin page and deletes every post on the page. This clears all posts and comments created by tests.
In theory, if we made so many posts in a single test that it spanned multiple pages we'd need to adjust this, but I started simple for now as that never happens.
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'm wondering if we shouldn't perform it as beforeAll
to support also the case where the previous run was interrupted by some random factor and cleanup could NOT be finished.
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.
Well, the first time the tests are run the entire setup is reset: https://github.com/WordPress/gutenberg/pull/8041/files#diff-cc6d2a226eaf023f937fb5813d954327R10
I guess doing it in either place is fine though, so we can change it to beforeEach
if you like. Actually, doing that might save us accepting the "Do you want to leave this page?" dialog so I'll give it a go 👍
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.
Just realised that global.page
doesn't exist in the beforeAll
.
We should really nix the globals in the test suite as well, they make it weird to reason about the state of tests and I don't think they're useful; but that's a separate issue I'll get into after this is fixed 😄
bin/install-wordpress.sh
Outdated
# Gutenberg script includes. | ||
. "$(dirname "$0")/includes.sh" | ||
|
||
CLI='cli' |
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 is all a bit messy, I might clean it up later 😅
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'm generally cool with this reorganisation, I just have a few comments. Nice work @tofumatt. 🙂
bin/install-wordpress.sh
Outdated
docker-compose run --rm $CLI option update siteurl "http://localhost:$HOST_PORT" >/dev/null | ||
fi | ||
|
||
# Reset the database so no posts/comments dirty up tests, if any exist. |
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 only want to do this if --e2e_tests
is defined.
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.
Yeah, fair enough. I like having mine reset but it would be unexpected. Will change 👍
. "$(dirname "$0")/includes.sh" | ||
|
||
# Set up WordPress site used for end-to-end (e2e) tests. | ||
. "$(dirname "$0")/install-wordpress.sh" --e2e_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.
A reinstall is pretty quick, and it guarantees you're getting a fresh state.
docker-compose.yml
Outdated
- ./test/e2e/test-plugins:/var/www/html/wp-content/plugins/gutenberg-test-plugins | ||
- ./test/e2e/test-mu-plugins:/var/www/html/wp-content/mu-plugins | ||
|
||
mysql_e2e_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.
I'm as excited as anyone about containers, but do we really need a seperate MySQL container here? Does it provide any isolation benefit that using a different DB_NAME
doesn't give?
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.
Is that a lot of work (mostly time wise) to create a new database per one tests run when booting tests?
Or use some WP-CLI incantation to restore it to a fresh install? In general, we are using WP Admin UI to do some things which WP-CLI, in theory, could do with one line, like activating/disabling plugins. I have no idea if it is easy to integrate, but I thought I ask :)
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 takes a few seconds to drop the database and re-install WordPress, I think the slowest part is Docker taking a snapshot of the cli box when the command runs.
I'm more concerned about having two MySQL servers running at the same, chewing up RAM.
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 agree.
I thought I mentioned it... maybe it's removed in a new commit, but yeah I would prefer a single DB too. I think the Docker container itself couldn't do one, but we should be able to easily create a new database used for the test runs on the existing DB/container.
I'll change this up to use the existing DB. I wanted to use the same WP-CLI container as well but we'd need to install stuff in WordPress to make RESTful WP-CLI commands work if I understand it correctly and the CLI container is lightweight enough. 🤷♂️
Yes, agreed. The general direction of having isolated DB instance in a clean state for every full tests run is great. I'd love to see it in |
I should also mention I considered using multisite to create a separate test site in the same container, but:
Just in case anyone mentions that as an alternative. I suppose it is but I think this is better. Also, @gziolo and I were chatting and he mentioned we could, maybe in the future, actually have a multisite where each test ran on a site, to up concurrency. Who knows if that'd work but it sounds cool/fast. 😮 |
b8fe2da
to
313c5d7
Compare
Improvements made, including omitting the second MySQL container and only resetting the database for the test site. |
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.
Noice! I like this change. 🙂
I just realised: I think I should add a notice to users who will encounter the need to re-run I'll add a little script to check for it... if it's complicated and requires further review I'll ping someone for a quick look 🙂 |
I noticed an increase in test instability recently and also the duration of the e2e tests increased significantly, I suspect it's coming from this PR. Do you think we can try to revert it and see if it's better to give us a bit more time to polish it? |
I could imagine slower tests, but what kind of instability are you seeing? If it’s causing really bad issues we should revert, but it’s a blocker to writing better, reliable tests 😊
- Matt (Sent from mobile)
… On 27 Jul 2018, at 11:42, Riad Benguella ***@***.***> wrote:
I noticed an increase in test instability recently and also the duration of the e2e tests increased significantly, I suspect it's coming from this PR. Do you think we can try to revert it, see if it's better to give us a bit more time to polish it?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or mute the thread.
|
A lot of "timeout" issues I didn't see before, I can't get the tests to pass reliably in one of my PRs. I agree with the premises of the PRs: more reliable and stable tests but it's just that it's less stable for now. I might try a revert PR to see if it's better and we can see how we can improve this later without introducing more instability. |
This reverts commit 1a0b22a.
After more tests, I noticed that clearing the travis cache can make things better. I'm not certain yet if the failures are equivalent to what we had before this PR. I'm not reverting at the moment, but we should definitely work on stabilizing those tests. |
This is a start to isolating our end-to-end (e2e) tests from our development environment so that tests are not affected by what's going on in the development environment.
This came about because I was writing e2e tests for #7941, but the existing comments elsewhere on the development site were causing a mismatch with the number of comments I expected in the development environment.
This is only a start because there are things that aren't cleared by the current
afterEach
code run after every test, but we can add to that as we go. The aim here is that every time we start e2e tests we should have a blank slate and after every test run we should also have a blank slate, without any requirements on developers to clean up the remnants of their tests.Fixes #7959
Fixes #8010
Testing Instructions
./bin/setup-local-env.sh
and make sure there are no error.npm run test-e2e
and see that the tests pass and do not create any data in your development site's database