Commit f7d1ec18 authored by Thong Kuah's avatar Thong Kuah

Clear all connections just before db:test:purge

For some reason connections are obtained during db:test:prepare,
specifically with config/initializers/1_postgresql_only.rb, and
config/initializers/postgres_partitioning.rb, and not released when we
come to the step where we purge the test db. Hence we force all
connections to be released first.
parent f22725d3
......@@ -170,6 +170,13 @@ namespace :gitlab do
Rake::Task['gitlab:db:create_dynamic_partitions'].invoke
end
desc "Clear all connections"
task :clear_all_connections do
ActiveRecord::Base.clear_all_connections!
end
Rake::Task['db:test:purge'].enhance(['gitlab:db:clear_all_connections'])
# During testing, db:test:load restores the database schema from scratch
# which does not include dynamic partitions. We cannot rely on application
# initializers here as the application can continue to run while
......
......@@ -20,6 +20,14 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
allow(Rake::Task['db:seed_fu']).to receive(:invoke).and_return(true)
end
describe 'clear_all_connections' do
it 'calls clear_all_connections!' do
expect(ActiveRecord::Base).to receive(:clear_all_connections!)
run_rake_task('gitlab:db:clear_all_connections')
end
end
describe 'mark_migration_complete' do
context 'with a single database' do
let(:main_model) { ActiveRecord::Base }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment