Skip to content

Commit

Permalink
Fix some NoMethodError (e,g #flush!) on ConnectionProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
gussan committed Jun 4, 2018
1 parent 27d2b28 commit 6f1e4a8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
32 changes: 23 additions & 9 deletions lib/active_record/turntable/pool_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def with_connection
yield proxy
end

delegate :connected?, :automatic_reconnect, :automatic_reconnect=, :checkout_timeout, :dead_connection_timeout,
:spec, :connections, :size, :reaper, :table_exists?, :query_cache_enabled, :enable_query_cache!, to: :proxy
delegate :connected?, :checkout_timeout, :automatic_reconnect, :automatic_reconnect=, :checkout_timeout, :checkout_timeout=, :dead_connection_timeout,
:spec, :connections, :size, :reaper, :table_exists?, :query_cache_enabled, :enable_query_cache!, :schema_cache, :schema_cache=, to: :proxy

%w(columns_hash column_defaults primary_keys).each do |name|
define_method(name.to_sym) do
Expand All @@ -30,18 +30,32 @@ def active_connection?
connection_pools_list.any?(&:active_connection?)
end

%w(disconnect!
release_connection
clear_all_connections!
clear_active_connections!
clear_reloadable_connections!
clear_stale_cached_connections!
verify_active_connections!).each do |name|
%w[
clear_active_connections!
clear_all_connections!
clear_reloadable_connections!
clear_stale_cached_connections!
disconnect
disconnect!
flush!
reap
release_connection
verify_active_connections!
].each do |name|
define_method(name.to_sym) do
connection_pools_list.each { |cp| cp.public_send(name.to_sym) }
end
end

%w[
clear_reloadable_connections
flush
].each do |name|
define_method(name.to_sym) do |args|
connection_pools_list.each { |cp| cp.public_send(name.to_sym, *args) }
end
end

def discard!
# Nothing to do
end
Expand Down
15 changes: 15 additions & 0 deletions spec/active_record/turntable/pool_proxy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "spec_helper"

describe ActiveRecord::Turntable::PoolProxy do
context "When initialized" do
subject { ActiveRecord::Turntable::PoolProxy.new(nil) }

UNSUPPORTED_PROXY_METHODS = %i[checkout checkin stat lock_thread= remove num_waiting_in_queue].freeze

context "Comparing original connection pool" do
(ActiveRecord::ConnectionAdapters::ConnectionPool.instance_methods(false) - UNSUPPORTED_PROXY_METHODS).each do |original_method|
it { is_expected.to be_respond_to(original_method) }
end
end
end
end

0 comments on commit 6f1e4a8

Please sign in to comment.