我正在使用parallel_tests
gem 在 CI 中运行我的 rails 6 应用程序测试。在日志中,我看到ENV[TEST_ENV_NUMBER]
正在创建所有 9 个数据库,然后它只是失败说这些数据库不存在。
我运行的命令是:
bin/bundle install
bin/bundle exec rake parallel:setup
bin/bundle exec rake parallel:spec
日志如下:
创建数据库'my_db_name4' 设置配置 ------------ (1 行) 创建数据库'my_db_name' 设置配置 ------------ (1 行) 创建数据库'my_db_name2' 设置配置 ------------ (1 行) 创建数据库'my_db_name5' 设置配置 ------------ (1 行) 创建数据库'my_db_name7' 设置配置 ------------ (1 行) 创建数据库'my_db_name8' 设置配置 ------------ (1 行) 创建数据库'my_db_name6' 设置配置 ------------ (1 行) 创建数据库'my_db_name3' 设置配置 ------------ (1 行) bin/bundle exec rake 并行:规范 耙中止! ActiveRecord::NoDatabaseError: FATAL: 数据库“my_db_name1”不存在 /usr/local/bundle/gems/activerecord-6.0.3/lib/active_record/connection_adapter/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>' 造成的: PG::ConnectionBad:致命:数据库“my_db_name1”不存在 /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>' 任务:TOP => db:abort_if_pending_migrations (通过使用 --trace 运行任务查看完整跟踪)``` 难道我做错了什么?我怀疑数据库在某处被破坏,但我不知道去哪里找。