-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Do not run rake test tasks with at_exit
#19435
Conversation
This is a good start, me and @senny were discussing this. |
Relying on |
a8d9040
to
8b02a24
Compare
For rake test tasks, call `Minitest.run` explicitly instead of using the `at_exit` hook. This executes test tasks at their specified position and not only at the end of the rake run. E.g. rake test:models other:task test:controllers This first runs the model tests, then other:task and finally the controller tests. Before this change, other:task was run first, then the model and controller tests were run in one go.
8b02a24
to
425d76c
Compare
I adjusted the commit to use |
run_tasks('test', 'dummy').tap do |output| | ||
assert_match "FooTest", output | ||
assert_no_match "Dummy", output | ||
assert_match "1 runs, 1 assertions, 1 failures", output |
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.
As far as I can tell, we are only matching if those output exist, and not the order of them.
We should match the order too, to test that at_exit
from Minitest is not running.
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.
The order is matched in test_run_test_task_before_others
. This test asserts that the dummy
task is not executed when the previous test task fails. As only "FooTest"
appears in the output, there is no order to test.
Interesting, I'd somehow missed this PR. I did some investigation into something similar in this Minitest issue. Since this commit, because of the "global" random ordering, typically some integration tests run before some unit tests. While I understand the desire to run all the tests in a single process (to avoid Rails environment load time), the fact that some integration tests are now run before some unit tests seems wrong to me. In my opinion, unit tests should give the fastest and most-specific feedback and should all be run first, even if they aren't run in a separate process. Also if any unit test fails, no integration tests should be run. Would you be open to making such a change and would it make sense to incorporate it into this PR or should it be a separate PR? |
@floehopper With Rails 5 we will be moving away from rake to run our tests (See this PR) for more details. Nonetheless, in my opinion a Minitest.run(["test/models", "test/controllers", "test/helpers"])
Minitest.run(["test/functional"])
Minitest.run(["test/integration"]) I don't think this should be the default behavior though. |
Yes, I agree with @senny. And that code is how you'd do it 👍 |
The benefit just doesn't sound that appealing. It's far simpler for us to just let Minitest randomize the tests 😄 |
Unit tests should run much quicker than integration tests and when they fail they give a much better indication of where the problem lies compared to a failing integration test. I think there is a significant advantage in running all the unit tests before any of the integration tests and I don't think it would make the code much more complicated to do so. However, I recognise that this suggestion is separate from the purpose of the changes in this PR, so I won't add any more comments here. |
Fixed in #19571. Thanks for your work ❤️ |
For rake test tasks, call
Minitest.run
explicitly instead of using theat_exit
hook. This executes test tasks at their specified position and not only at the end of the rake run.E.g.
This first runs the model tests, then other:task and finally the controller tests. Before this change, other:task was run first, then the model and controller tests were run in one go.
If a test task fails, rake exits with exit code 1 (same as before) without running the remaining tasks.
Fixes #17708.