Skip to content

Commit

Permalink
Add failing test to demonstrate 'SET' matching bug
Browse files Browse the repository at this point in the history
  • Loading branch information
righi committed Apr 26, 2015
1 parent 9dda370 commit 36de471
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,38 @@
'select * from users where name = "lock in share mode"' => false
}.each do |sql, should_go_to_master|

it "determines if \"#{sql}\" #{should_go_to_master ? 'requires' : 'does not require'} master" do
it "determines that \"#{sql}\" #{should_go_to_master ? 'requires' : 'does not require'} master" do
proxy = klass.new(config(1,1))
expect(proxy.master_for?(sql)).to eq(should_go_to_master)
end

end


{
"SET @@things" => true,
"INSERT INTO wisdom ('The truth will set you free.')" => false,
"INSERT INTO wisdom ('The truth will\nset you free.')" => false
}.each do |sql, should_send_to_all_connections|

it "determines that \"#{sql}\" #{should_send_to_all_connections ? 'should' : 'should not'} be sent to all underlying connections" do
proxy = klass.new(config(1,1))
proxy.master_pool.connections.each{|con| expect(con).to receive(:execute).with(sql).once}
proxy.slave_pool.connections.each do |con|
if should_send_to_all_connections
expect(con).to receive(:execute).with(sql).once
else
expect(con).to receive(:execute).with(sql).never
end
end

it 'should send SET operations to all underlying connections' do
proxy = klass.new(config(1,1))
proxy.master_pool.connections.each{|con| expect(con).to receive(:execute).with('SET @@things').once }
proxy.slave_pool.connections.each{|con| expect(con).to receive(:execute).with('SET @@things').once }
proxy.execute(sql)

proxy.execute("SET @@things")
if should_send_to_all_connections
expect(proxy.master_context).to be_nil
end
end

expect(proxy.master_context).to be_nil
end

{
Expand Down

0 comments on commit 36de471

Please sign in to comment.