-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix on Ruby 3 #283
Fix on Ruby 3 #283
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,19 +24,23 @@ def hijack_method(*method_names) | |
self.hijack_methods |= method_names | ||
|
||
method_names.each do |method_name| | ||
define_method method_name do |*args, &block| | ||
define_method(method_name) do |*args, &block| | ||
appropriate_connection(method_name, args) do |con| | ||
con.send(method_name, *args, &block) | ||
end | ||
end | ||
|
||
ruby2_keywords method_name if Module.private_method_defined?(:ruby2_keywords) | ||
end | ||
end | ||
|
||
def send_to_all(*method_names) | ||
method_names.each do |method_name| | ||
define_method method_name do |*args| | ||
send_to_all method_name, *args | ||
define_method(method_name) do |*args| | ||
send_to_all(method_name, *args) | ||
end | ||
|
||
ruby2_keywords method_name if Module.private_method_defined?(:ruby2_keywords) | ||
end | ||
end | ||
|
||
|
@@ -45,9 +49,11 @@ def control_method(*method_names) | |
self.control_methods |= method_names | ||
|
||
method_names.each do |method_name| | ||
define_method method_name do |*args, &block| | ||
define_method(method_name) do |*args, &block| | ||
control&.send(method_name, *args, &block) | ||
end | ||
|
||
ruby2_keywords method_name if Module.private_method_defined?(:ruby2_keywords) | ||
end | ||
end | ||
end | ||
|
@@ -118,20 +124,20 @@ def strategy_class_for(strategy_name) | |
|
||
def method_missing(m, *args, &block) | ||
if METHOD_MISSING_SKIP.include?(m) | ||
return super(m, *args, &block) | ||
return super | ||
end | ||
|
||
any_connection do |con| | ||
if con.respond_to?(m) | ||
con.public_send(m, *args, &block) | ||
elsif con.respond_to?(m, true) | ||
con.__send__(m, *args, &block) | ||
if con.respond_to?(m, true) | ||
con.send(m, *args, &block) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Subtle regression here. We'll now call a private Example c.send(:select, "select 1")
*** TypeError Exception: wrong argument type String (expected Array)
c.public_send(:select, "select 1")
(2.1ms) select 1
#<ActiveRecord::Result:0x00007f8784b4e7f0 @columns=["1"], @rows=[[1]], @hash_rows=nil, @column_types={}> This is the cause of #326 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for catching this. TIL about If you can send a PR and maybe add a spec to prevent a regression I'll get it merged ASAP. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure thing. Thanks @mlarraz. |
||
else | ||
super(m, *args, &block) | ||
super | ||
end | ||
end | ||
end | ||
|
||
ruby2_keywords :method_missing if Module.private_method_defined?(:ruby2_keywords) | ||
|
||
def respond_to_missing?(m, include_private = false) | ||
any_connection do |con| | ||
con._makara_connection.respond_to?(m, true) | ||
|
@@ -157,15 +163,16 @@ def disconnect! | |
|
||
protected | ||
|
||
|
||
def send_to_all(method_name, *args) | ||
# replica pool must run first to allow for replica --> master failover without running operations on master twice. | ||
handling_an_all_execution(method_name) do | ||
@replica_pool.send_to_all method_name, *args | ||
@master_pool.send_to_all method_name, *args | ||
@replica_pool.send_to_all(method_name, *args) | ||
@master_pool.send_to_all(method_name, *args) | ||
end | ||
end | ||
|
||
ruby2_keywords :send_to_all if Module.private_method_defined?(:ruby2_keywords) | ||
|
||
def any_connection | ||
if @master_pool.disabled | ||
@replica_pool.provide do |con| | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,13 @@ | |
Test::User.exists? # flush other (schema) things that need to happen | ||
|
||
con = connection.replica_pool.connections.first | ||
expect(con).to receive(:exec_query).with(/SELECT\s+1\s*(AS one)?\s+FROM .?users.?\s+LIMIT\s+.?1/, any_args).once.and_call_original | ||
|
||
expect(con).to receive(:exec_query) do |query| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this change is causing a failure for this matrix run: https://github.com/instacart/makara/pull/283/checks?check_run_id=1730065278 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this spec flaps on jruby for some reason. It's the same on master now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
expect(query).to match(/SELECT\s+1\s*(AS one)?\s+FROM .?users.?\s+LIMIT\s+.?1/) | ||
end.once. | ||
# and_call_original # Switch back to this once https://github.com/rspec/rspec-mocks/pull/1385 is released | ||
and_wrap_original { |m, *args| m.call(*args.first(3)) } | ||
|
||
Test::User.exists? | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need
public_send
here becausefoo.bar=(...)
is not valid syntax in Ruby 3.0 (even thoughfoo.bar(...)
is)