-
Notifications
You must be signed in to change notification settings - Fork 21.7k
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
Parallel test databases are truncated before each run, but non-parallel test databases are not #46820
Comments
In the past, the test suite has been flaky, and didn't seem to truncate tables from previous runs. The root cause of that might be related to [rails/rails#46820][]. In the meantime, while that is resolved, this commit adds a line to [parallelize][] to the test suite, and some corresponding `.sqlite3` ignore values to the `.gitignore`. [rails/rails#46820]: rails/rails#46820 [parallelize]: https://edgeapi.rubyonrails.org/classes/ActiveSupport/TestCase.html#method-c-parallelize
In the past, the test suite has been flaky, and didn't seem to truncate tables from previous runs. The root cause of that might be related to [rails/rails#46820][]. In the meantime, while that is resolved, this commit adds a line to [parallelize][] to the test suite, and some corresponding `.sqlite3` ignore values to the `.gitignore`. [rails/rails#46820]: rails/rails#46820 [parallelize]: https://edgeapi.rubyonrails.org/classes/ActiveSupport/TestCase.html#method-c-parallelize
The data being inserted into the database is happening before the test databases are created. If you want to insert data into the parallel databases you need to hook into the same callback that parallel testing uses. This is documented here https://guides.rubyonrails.org/testing.html#parallel-testing-with-processes. I think the docs could be improved, but calling a manual insert before the test databases are established will always cause the tests to fail in parallel. |
Geez, how did I miss that. This works as expected: https://github.com/ghiculescu/parallel-tests-repro/compare/use-parallel-setup Thanks for the help @eileencodes |
I ran into a discrepancy with parallelization when it comes to when fixture data is available to the forked processes vs non-parallelized runs. Everything works fine without parallelization but failed with parallelization due to fixture data not yet being available in the database. I worked around the issue by manually loading the fixtures I needed in parallelize_setup do |i|
ActiveRecord::FixtureSet.create_fixtures(Rails.root.join("test/fixtures"), "accounts")
end |
That seems like a bug, fixtures should get loaded automatically in either setup. Could you create an issue with more derail? |
Steps to reproduce
Repro here: https://github.com/ghiculescu/parallel-tests-repro. The key bits are as follows.
In the test helper:
The test:
This just confirms that the static data was successfully loaded and is available to the test.
Expected behavior
I expect the test to pass if you run in singular or in parallel.
Actual behavior
Running not in parallel passes.
Running in parallel fails.
It is failing because
rails/activerecord/lib/active_record/test_databases.rb
Line 8 in 40a1f3a
calls
rails/activerecord/lib/active_record/tasks/database_tasks.rb
Line 389 in 40a1f3a
which truncates all tables. The equivalent does not happen if you aren't running in parallel.
I tried commenting out that line, and all tests still passed, but I assumed there's a reason for it (though I can't think of one...) so wanted to make an issue for discussion first.
System configuration
Rails version:
main
Ruby version: 3.2
The text was updated successfully, but these errors were encountered: