-
Notifications
You must be signed in to change notification settings - Fork 483
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
Switching from :transaction to :truncation for some tests doesn't work #652
Comments
Hi, @wjessop , thanks for the issue! At a glance, my first guess is that the |
Fat fingered the Close and comment button instead of the Comment button 😅 |
Thanks for the reply @botandrose! I found some config.around(:each) do |example|
if example.metadata[:bypass_cleaner]
example.run
else
DatabaseCleaner.cleaning do
example.run
end
end
end I commented it out and the records are now available outside the process, and the test passes, but rather confusingly the strategy still reports as transactional: (byebug) DatabaseCleaner[:active_record].strategy
#<DatabaseCleaner::ActiveRecord::Transaction:0x00007f8f78b8d300 @db=:default> I've got Spring disabled BTW, just to eliminate that as a possible issue. |
Had the same problem and removed the config.before(:each) do
DatabaseCleaner.start
end
config.append_after(:each) do
DatabaseCleaner.clean
end |
…used In some tests, we might ensure that a transaction has been rolled back (e.g. if an error occurred). Since currently we do not support transactions within other transactions, those tests use the `omit_database_transaction` flag which means the test does not get wrapped in a transaction. The problem is that these tests now leave data lying around after running. Our original plan to solve this was to find a way to still rollback in the app despite already running in a transaction. However Sequel does not support naming a transaction from what I can tell, and anyway there is no way to pass args to the transaction via the `DatabaseCleaner` gem. Going through some issues I found this issue: DatabaseCleaner/database_cleaner#652 Basically this person wants to read data from the DB in another app, but in only some tests. He took the approach of switching "strategy" to accomplish it. I am basically stealing the same idea since it seems to work and was quite trivial. The big downside is that those tests will probably take longer to run, luckily only 5 tests use this flag currently in echo, so this should not be too big of a problem.
…used (#109) In some tests, we might ensure that a transaction has been rolled back (e.g. if an error occurred). Since currently we do not support transactions within other transactions, those tests use the `omit_database_transaction` flag which means the test does not get wrapped in a transaction. The problem is that these tests now leave data lying around after running. Our original plan to solve this was to find a way to still rollback in the app despite already running in a transaction. However Sequel does not support naming a transaction from what I can tell, and anyway there is no way to pass args to the transaction via the `DatabaseCleaner` gem. Going through some issues I found this issue: DatabaseCleaner/database_cleaner#652 Basically this person wants to read data from the DB in another app, but in only some tests. He took the approach of switching "strategy" to accomplish it. I am basically stealing the same idea since it seems to work and was quite trivial. The big downside is that those tests will probably take longer to run, luckily only 5 tests use this flag currently in echo, so this should not be too big of a problem.
So, I have some tests that need truncation because I am testing the whole Sidekiq stack and as a separate process Sidekiq needs to be able to see the records created in the original process. I want to keep the suite in general as
:transaction
though as the rest of the tests are fine with that strategy.To do this I add come config to the rspec config:
Then add metadata to the test:
The problem is that Sidekiq gets ActiveRecord not found errors, and sure enough, there are no rows available to on a separate database (postgres) connection:
If I stick
byebug
in the test I can confirm that there are in fact records:but the strategey does seem to be truncation:
If I re-run the test after configuring truncation for all of the tests:
I can see that the strategy in the test is the same:
and the records are available in the test:
but this time the records are also available in the database:
and my test passes. These are the versions of relevant gems I am using
Upgrading database cleaner
So I noticed as I was gathering the version data that database_cleaner was out of date (I could have sworn that I updated it already!). Anyway, after upgrading database_cleaner it now looks like inside the test the reported strategy matches the observed behaviour:
This is despite my strategy switch seeming to work OK in the rspec config:
and as the test is using transactions not truncation the external process can't see the records and the test fails. Any ideas what's going on here?
The text was updated successfully, but these errors were encountered: