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
before_all in minitest leaks data across test classes #266
Comments
Do you use threads for parallelization ( As I see, we use a class instance variable here, which is not thread-safe: test-prof/lib/test_prof/recipes/minitest/before_all.rb Lines 9 to 18 in 5d26319
|
thanks @palkan for looking into this. It happens when executing it with workers, so no threads. |
Oh, that's interesting. That means that our activation code is not triggered and data is created outside of transactions. Do you use fixtures or multiple databases or anything else dealing with DBs in your tests? Any details would be appreciated, so we can reproduce it ourselves. |
We are using factory_bot (no fictures) and the standard rails 6 parallel test setup where multiple databases. What is really confusing, that the spanning transaction does not only spans around all tests in a test classes but also around tests in other test classes. It might be related, that rails is running tests in any order across all assigned tests. Does this make sense? |
As far as I can see, Rails enqueues methods one by one to be executed in the same order (using a FIFO queue). So, we shouldn't have the situation when tests from different suites are executed by the same worker interchangeably: |main process|
|
|
{A#test_one, A#test_three,A#test_two, B#test_two,B#test_one,B#test_three}
|
queue
/ \
/ \
|worker #1| |worker #2|
| |
{A#test_one,A#test_three,B#test_two} {A#test_two,B#test_one,B#test_three} We shouldn't have situations like To figure out what's going on it would be helpful to see some logs:
|
Hey @quorak! Any updates on this? |
Tell us about your environment
Ruby Version:
2.7.3
Framework Version (RSpec, Minitest, FactoryGirl, Rails, whatever):
minitest (5.18.0)
factory_bot (5.2.0)
rails (6.1.7.3)
TestProf Version:
test-prof (1.2.1)
What did you do?
I have 2 test classes, one of those with
before_all
where I create some data.What did you expect to happen?
I would expect not to see data from
IndexControllerTest.before_all
while running tests inSomeOtherControllerTest
What actually happened?
I saw data from another test classes before_all data.
This only happens during parallel test execution. It looks like, tests are running randomly and the test from
SomeOtherControllerTest
is using a open transaction fromIndexControllerTest
that has been filled with data frombefore_all
and has not been rolled back yet.Needless to day, that this is a great idea and a awesome gem!
Thanks for helping!
The text was updated successfully, but these errors were encountered: