A platform for community discussion. Free, open, simple.
DEV: Clone instead of migrating databases for parallel tests (#44104)
Alan Guo Xiang Tanccf306f9628e
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.ymlindex 121bbfd1216..b7ea852a104 100644--- a/.github/workflows/tests.yml+++ b/.github/workflows/tests.yml@@ -192,11 +192,11 @@ jobs:- parallel:- name: Migrate database- run: bin/rake db:migrate-- - name: Create and migrate parallel databases- if: env.USES_PARALLEL_DATABASES == 'true'- run: bin/rake parallel:create parallel:migrate+ run: |+ bin/rake db:migrate+ if [ "$USES_PARALLEL_DATABASES" = "true" ]; then+ bin/rake parallel:clone+ fi- name: Check Annotationsif: matrix.build_type == 'backend' && (matrix.target == 'core' || matrix.target == 'plugins')diff --git a/lib/tasks/parallel_tests.rake b/lib/tasks/parallel_tests.rakeindex ff00c5afd80..1baa84dca8a 100644--- a/lib/tasks/parallel_tests.rake+++ b/lib/tasks/parallel_tests.rake@@ -1,3 +1,26 @@# frozen_string_literal: true-require "parallel_tests/tasks" if Rails.env.local?+if Rails.env.local?+ require "parallel_tests"+ require "parallel_tests/tasks"++ namespace :parallel do+ desc "Clone the test database for parallel test processes"+ task :clone, [:count] => :environment do |_, args|+ number_of_processes = ParallelTests.determine_number_of_processes(args[:count])+ database = ActiveRecord::Base.connection_db_config.database++ ActiveRecord::Base.remove_connection++ Parallel.each(1..number_of_processes, in_processes: 4) do |process_number|+ system(+ "createdb",+ "--maintenance-db=postgres",+ "--template=#{database}",+ "#{database}_#{process_number}",+ exception: true,+ )+ end+ end+ end+end