0

I am using parallel_tests gem for running my rails 6 app tests in CI. In logs, I see all 9 databases with ENV[TEST_ENV_NUMBER] are being created, and then it just fails saying that these databases do not exist.

The commands I run are:

bin/bundle install bin/bundle exec rake parallel:setup bin/bundle exec rake parallel:spec 

Logs are the following:

 Created database 'my_db_name4' set_config ------------ (1 row) Created database 'my_db_name' set_config ------------ (1 row) Created database 'my_db_name2' set_config ------------ (1 row) Created database 'my_db_name5' set_config ------------ (1 row) Created database 'my_db_name7' set_config ------------ (1 row) Created database 'my_db_name8' set_config ------------ (1 row) Created database 'my_db_name6' set_config ------------ (1 row) Created database 'my_db_name3' set_config ------------ (1 row) bin/bundle exec rake parallel:spec rake aborted! ActiveRecord::NoDatabaseError: FATAL: database "my_db_name1" does not exist /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:50:in `rescue in postgresql_connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:33:in `postgresql_connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1119:in `retrieve_connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_handling.rb:221:in `retrieve_connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_handling.rb:189:in `connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:261:in `block (3 levels) in <main>' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:258:in `each' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:258:in `flat_map' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:258:in `block (2 levels) in <main>' /usr/local/bundle/gems/parallel_tests-3.0.0/lib/parallel_tests/tasks.rb:71:in `block in check_for_pending_migrations' /usr/local/bundle/gems/parallel_tests-3.0.0/lib/parallel_tests/tasks.rb:69:in `each' /usr/local/bundle/gems/parallel_tests-3.0.0/lib/parallel_tests/tasks.rb:69:in `check_for_pending_migrations' /usr/local/bundle/gems/parallel_tests-3.0.0/lib/parallel_tests/tasks.rb:183:in `block (3 levels) in <main>' bin/bundle:113:in `load' bin/bundle:113:in `<main>' Caused by: PG::ConnectionBad: FATAL: database "my_db_name1" does not exist /usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `initialize' /usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `new' /usr/local/bundle/gems/pg-1.2.3/lib/pg.rb:58:in `connect' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/postgresql_adapter.rb:46:in `postgresql_connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1119:in `retrieve_connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_handling.rb:221:in `retrieve_connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_handling.rb:189:in `connection' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:261:in `block (3 levels) in <main>' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:258:in `each' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:258:in `flat_map' /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/railties/databases.rake:258:in `block (2 levels) in <main>' /usr/local/bundle/gems/parallel_tests-3.0.0/lib/parallel_tests/tasks.rb:71:in `block in check_for_pending_migrations' /usr/local/bundle/gems/parallel_tests-3.0.0/lib/parallel_tests/tasks.rb:69:in `each' /usr/local/bundle/gems/parallel_tests-3.0.0/lib/parallel_tests/tasks.rb:69:in `check_for_pending_migrations' /usr/local/bundle/gems/parallel_tests-3.0.0/lib/parallel_tests/tasks.rb:183:in `block (3 levels) in <main>' bin/bundle:113:in `load' bin/bundle:113:in `<main>' Tasks: TOP => db:abort_if_pending_migrations (See full trace by running task with --trace)``` Am I doing something wrong? I suspect databases are being destroyed somewhere, but I don't know where to look. 
2
  • 1
    Just a observation. In logs I can't find my_db_name1 being created and that's the error it's showing. Commented Jun 29, 2020 at 16:26
  • Indeed! That is interesting! Yet I found the problem, it's still interesting for me, why it wasn't created Commented Jun 30, 2020 at 7:56

1 Answer 1

2

So, that was quite easy, but hard to find =( I found out that I had TEST_ENV_NUMBER env variable set to 1 in CI. So, it tried to connect to the database my_db_name1 from every process, I guess. Once I removed this variable, everything started to work just fine. It's still interesting for me why this database has not been created as pointed by @cdadityang in the comments.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.