DatabaseCleaner / database_cleaner

Strategies for cleaning databases in Ruby. Can be used to ensure a clean state for testing.
https://www.rubydoc.info/github/DatabaseCleaner/database_cleaner
MIT License
2.93k stars 484 forks source link

ActiveRecord::ConnectionNotEstablished in random places #716

Open stiig opened 4 weeks ago

stiig commented 4 weeks ago

Hi team, sometimes we have this error during running the tests

Randomized with seed 38777
..........................F
An error occurred in an `after(:context)` hook.
Failure/Error: DatabaseCleaner.clean_with(:truncation, except: %i[translations])

ActiveRecord::ConnectionNotEstablished:
  connection to server at "127.0.0.1", port 5432 failed: server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
Randomized with seed 59497
...........*..................................................F
An error occurred in an `after(:context)` hook.
Failure/Error: DatabaseCleaner.clean_with(:truncation, except: %i[translations])

ActiveRecord::ConnectionNotEstablished:
  connection to server at "127.0.0.1", port 5432 failed: FATAL:  the database system is shutting down

we run them in parallel

image

and I have no idea where to find roots of the problem

I tried to set reaping_frequency: 0 setting but it didn't help (logs from runs with this setting)

Versions:

Tests crash in random places and often a restart helps, we don't have something special for database cleaner, our config: rails_helper.rb:

  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
  end

  config.around do |example|
    DatabaseCleaner.cleaning do
      example.run
    end
  end

  config.after(:all) do
    DatabaseCleaner.clean_with(:truncation, except: %i[translations])
  end