From f42fa9f599fa11ed08cb378212fb3260ea871eef Mon Sep 17 00:00:00 2001 From: zinduolis Date: Wed, 3 Sep 2025 10:18:20 +1000 Subject: [PATCH] Add connection pool cleanup after each example in RSpec --- spec/spec_helper.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ecaa803b1..be93ad5aa 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -139,6 +139,11 @@ RSpec.configure do |config| end end + # Ensure every example starts with a fresh connection pool + config.after(:each) do + disconnect_all_active_record! + end + def server_teardown(webdriver, server_pid, server_pids) webdriver.quit rescue StandardError => e @@ -196,15 +201,15 @@ require 'socket' # --- HARD fork-safety: disconnect every pool/adapter we can find --- def disconnect_all_active_record! - print_info "Entering disconnect_all_active_record!" + # print_info "Entering disconnect_all_active_record!" if defined?(ActiveRecord::Base) - print_info "Disconnecting ActiveRecord connections" + # print_info "Disconnecting ActiveRecord connections" handler = ActiveRecord::Base.connection_handler if handler.respond_to?(:connection_pool_list) - print_info "Using connection_pool_list" + # print_info "Using connection_pool_list" handler.connection_pool_list.each { |pool| pool.disconnect! } elsif handler.respond_to?(:connection_pools) - print_info "Using connection_pools" + # print_info "Using connection_pools" handler.connection_pools.each_value { |pool| pool.disconnect! } end else