-
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
truncation in capybara tests results in rspec freezing (while deletion works) #273
Comments
We're having similar issues, but only when we use capybara-webkit as well... It seems to only affect 'js:true' testcases. Even on truncation our tests will (rarely but consistently) hang forever (inspecting the call stack/debugging shows that it hangs while starting the Capybara Brick server). This thread https://groups.google.com/forum/#!topic/ruby-capybara/sgBkBKVXf_w seems to indicate that it might have something to do with the way I'm intermingling Database checks with Javascript capybara interactions, but I've been unable to isolate them. |
At least for me, this was a deadlock between DatabaseCleaner truncating tables and RSpec starting a transaction for the test. Not sure of the RSpec conventions here, but adding this to spec_helper.rb fixed it for me:
I'm using Postgres. Not sure that matters. In any case, the idea is to not mix DatabseCleaner truncation or deletion with RSpec transactions. |
I'm also seeing database_cleaner hang when My RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with :truncation
end
config.around(:each) do |example|
if example.metadata[:js]
DatabaseCleaner.strategy = :truncation
else
DatabaseCleaner.strategy = :transaction
end
DatabaseCleaner.start
example.run
DatabaseCleaner.clean
end
end |
Also seeing a lot of hanging behaviour. The edit: It doesn't seem to clean up after features properly though.... getting failing tests due to leftover data from previous features |
Not sure if this is helpful but we (@vormwald) had a weird hanging issue as well. Changing... config.around(:each) do |example|
DatabaseCleaner.strategy = example.metadata[:js] ? :deletion : :transaction
DatabaseCleaner.cleaning do
example.run
end
end ...to... config.before(:each) do |example|
DatabaseCleaner.strategy = example.metadata[:js] ? :deletion : :transaction
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end ...fixed our issue. |
I think this might be related to #292. I was running into this on Rails 4.1 when running a sequence of js, then non-js, then js specs again. Switching to always using Disconnecting all connections at the end of the EDIT: Nevermind, this didn't actually fix it! config.around do |example|
use_truncation_strategy = example.metadata[:js] || example.metadata[:multithread]
DatabaseCleaner.strategy = use_truncation_strategy ? :deletion : :transaction
DatabaseCleaner.cleaning do
example.run
end
ActiveRecord::Base.connection_pool.disconnect!
end |
Switching from config.before(:each) do |spec|
DatabaseCleaner.strategy = spec.metadata[:js] ? :deletion : :transaction
DatabaseCleaner.start
end
config.after(:each) do |spec|
DatabaseCleaner.clean
begin
ActiveRecord::Base.connection.send :rollback_transaction_records, true
rescue
end
ActiveRecord::Base.connection_pool.disconnect! if spec.metadata[:js]
end |
Had this bug with Rails 4.1.8 + RSpec 3.1.0 + Turnip 1.2.4 + Capybara 2.4.4 + Poltergeist 1.5.1 + DatabaseCleaner 1.3.0 + Postgres 9.3 using an around filter to switch over cleaning strategies. Dozens of database transactions were left open, eventually making so no specs could execute anymore (the rspec runner just hang there waiting forever). The solution was simply to using a before(:each) + after(:each) filter under RSpec.configure like this: config.before(:each) do |example|
if [:feature, :request].include? example.metadata[:type]
DatabaseCleaner.strategy = :truncation
else
DatabaseCleaner.strategy = :transaction
end
DatabaseCleaner.start
end
config.after(:each) do |example|
DatabaseCleaner.clean
end |
Unfortunately nothing here has fixed the problem in my app. The test running sits there doing nothing, and when I start a Postgres console and check the |
@Karpah Can you paste your spec_helper here? |
I am experiencing the same issue: This config causes specs to freeze: RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.around(:each) do |example|
DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
DatabaseCleaner.cleaning do
example.run
end
end
end Example provided by @lucashungaro fixes the issue, however I'm not sure why this happens. Any ideas? |
@airatshigapov It's probably an issue with around filters not working properly, so the transactions are never closed. |
May be this solution will help you: teamcapybara/capybara#1089 (comment) |
I believe this is an issue with the transactions not being closed. I had an issue deletion and truncation and was able to hack a solution by rolling back open transactions before deleting or truncating my tables This should be taken care of in the |
I'm having the same experience that @lucashungaro mentions. Using an |
Depending on the order of test runs, there would sometime be failures with a MySQL Lock Wait Timeout. This is due to an issue with database_cleaner and unclosed transactions. The following change works around this issue. See DatabaseCleaner/database_cleaner#273 for more details.
Experiencing same behavior. My config looks very much like airatshigapov's and I can confirm that dropping the |
Note: the current example is overly lengthy. I would prefer to use something like: config.around(:each) do |example| DatabaseCleaner.strategy= example.metadata[:js] ? :truncation : :transaction DatabaseCleaner.cleaning do example.run end end However we should wait till this issue is solved: DatabaseCleaner#273
Note: I could have used an around(:each) block as in the ordinary RSpec example but there's currently an open issue that might affect many users: DatabaseCleaner#273
I managed to solve the problem by taking out config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do |example|
DatabaseCleaner.strategy = example.metadata[:js] ? :deletion : :transaction
DatabaseCleaner.start
end
config.after(:each) do
Capybara.reset_sessions!
DatabaseCleaner.clean
end |
This thread helped me to find a fix for my problem, so I'll just post the fix here in case it's helpful for anyone:
I'm not sure why the extra Just a bit more background on the issue I encounter since the above might not solve all the issues expressed on this thread: Some feature specs were either taking too long or not exiting correctly, so it left a lock on the database, which caused all subsequent database-dependent specs to run extremely slow and then fail with this error:
|
Using
and the code in my pull request #364 I was able to resolve this issue where open transactions were left on various connections to the database. Can someone else see if this helps? |
Note: I could have used an around(:each) block as in the ordinary RSpec example but there's currently an open issue that might affect many users: DatabaseCleaner#273
@claptimes5 you deserve a medal. I've been pulling my hair of for the last 8 hours because of this issue. Your PR fixed it. Thanks a bunch!! Added this to my Gemfile: gem 'database_cleaner', github: 'DatabaseCleaner/database_cleaner', ref: 'b8edac6bd04fb89a267201fa8d47066d511fd9de' |
@karlingen thanks!! I guess this issue can be closed? @etagwerker |
@claptimes5 You're right sir. Thank you! |
@etagwerker @bmabey @JonRowe plans to have this fix rolled out? I'm currently using master in my gemfile :/ |
@rafaelsales instead of using master you could lock it to a certain commit. gem 'database_cleaner', github: 'DatabaseCleaner/database_cleaner', ref: 'b8edac6bd04fb89a267201fa8d47066d511fd9de' |
@rafaelsales Here it is: http://databasecleaner.github.io/2015/09/01/v1-5-0-is-out/ but @karlingen's suggestion should've worked before this release. |
Depending on the order of test runs, there would sometime be failures with a MySQL Lock Wait Timeout. This is due to an issue with database_cleaner and unclosed transactions. The following change works around this issue. See DatabaseCleaner/database_cleaner#273 for more details.
I found out that this code (necessary to truncate in case we are testing with capybara) makes RSpec freeze right after running capybara tests, while the same code with :deletion strategy works smoothly.
As a matter of fact, the following code works for truncation, which makes me think that DatabaseCleaner.start must be run for truncation as well.
I don't know whether this is a bug or a some kinds of choice due to some reasons, however I felt it was worth pointing it out.
The text was updated successfully, but these errors were encountered: