Skip to content
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

Invoking database cleaner between retries #29

Closed
swaroopmurthy opened this issue Jul 8, 2015 · 4 comments
Closed

Invoking database cleaner between retries #29

swaroopmurthy opened this issue Jul 8, 2015 · 4 comments

Comments

@swaroopmurthy
Copy link

We have a flaky test suite of >2500 tests that invokes DatabaseCleaner between tests. Despite having a retry count of 3, we're seeing issues like unique constraint violated and record already exists...

Is there a way to explicitly invoke DatabaseCleaner between each retry attempt?

@michaelglass
Copy link
Contributor

there is no current api exposed for this functionality, see #33 if you want to add it!

@tye
Copy link

tye commented Aug 23, 2017

If you put DatabaseCleaner in before/after hooks instead of an around hook then your db will get cleaned between retries.

My rspec config looks something like this:

config.before(:each) do |example|
  DatabaseCleaner.start
end

config.after(:each) do |example|
  Capybara.reset_sessions! if example.metadata[:js]
  DatabaseCleaner.clean
end

config.around(:each) do |example|
  if example.metadata[:js]
    example.run_with_retry retry: 3
  else
    example.run
  end
end

If you're using Capybara you will need to call Capybara.reset_sessions! before cleaning the database in the after hook.

@michaelglass
Copy link
Contributor

@abrom just added between retry hooks, too (#50)

@joao-esteves
Copy link

joao-esteves commented May 4, 2023

Came across this and it should be helpful to leave my findings.

Unlike what's said above, DatabaseCleaner.cleaning do inside an around hook is cleaning the database between retries as of now. It was something else polluting my DB.

Check your retry_callback. In my case, I was printing a variable from a macro for debugging. It is an ActiveRecord object with FactoryGirl. The thing is that DatabaseCleaner was removing it from the DB before this method, so by printing the variable I was rerunning the macro and reinserting it in the DB with no DatabaseCleaner.cleaning block to remove it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants