DEV: correct parallel specs rake tasks

This used to work due to side effects.

`rake parallel:migrate` used to work very inconsistently and would only migrate
some of the databases.

This introduces the recommended change to db.yml so the correct database is
found based off TEST_ENV_NUMBER if for some reason we did not set it using
RAILS_DB

Also avoids a bunch of schema dumping which is not needed when migrating
parallel specs



DB number 1 is very odd cause for whatever reason parallel spec is not
setting it.
This commit is contained in:
Sam Saffron 2019-12-31 14:07:44 +11:00
parent f04f6cbf01
commit 412e1ebbe2
3 changed files with 22 additions and 4 deletions

View File

@ -16,10 +16,23 @@ development:
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
<%
test_db = ENV["RAILS_DB"]
if !test_db.present?
test_db = "discourse_test"
if num = ENV["TEST_ENV_NUMBER"]
num = num.presence || "1"
test_db += "_#{num}"
end
end
%>
test:
prepared_statements: false
adapter: postgresql
database: <%= ENV["RAILS_DB"] ? ENV["RAILS_DB"] : "discourse_test" %>
database: <%= test_db %>
min_messages: warning
pool: 5
timeout: 5000

View File

@ -9,6 +9,8 @@ pre-commit:
run: yarn eslint --ext .es6 -f compact {staged_files}
yaml-syntax:
glob: "*.{yaml,yml}"
# database.yml is an erb file not a yaml file
exclude: "database.yml"
run: bundle exec yaml-lint {staged_files}
commands: &commands

View File

@ -68,20 +68,23 @@ end
# we need to run seed_fu every time we run rake db:migrate
task 'db:migrate' => ['load_config', 'environment', 'set_locale'] do |_, args|
ActiveRecord::Tasks::DatabaseTasks.migrate
Rake::Task['db:_dump'].invoke
if !Discourse.is_parallel_test?
Rake::Task['db:_dump'].invoke
end
SeedFu.seed(DiscoursePluginRegistry.seed_paths)
unless Discourse.skip_post_deployment_migrations?
if !Discourse.skip_post_deployment_migrations?
puts
print "Optimizing site icons... "
SiteIconManager.ensure_optimized!
puts "Done"
end
if MultisiteTestHelpers.load_multisite?
if !Discourse.is_parallel_test? && MultisiteTestHelpers.load_multisite?
system("RAILS_DB=discourse_test_multisite rake db:migrate")
end
end