File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -501,7 +501,7 @@ def check(client)
501501 end
502502
503503 if role != @role
504- disconnect
504+ client . disconnect
505505 raise ConnectionError , "Instance role mismatch. Expected #{ @role } , got #{ role } ."
506506 end
507507 end
Original file line number Diff line number Diff line change @@ -147,4 +147,32 @@ def test_sentinel_with_auth
147147 assert_equal commands [ :s1 ] , [ %w[ get-master-addr-by-name master1 ] ]
148148 assert_equal commands [ :m1 ] , [ %w[ auth foo ] , %w[ role ] ]
149149 end
150+
151+ def test_sentinel_role_mismatch
152+ sentinels = [ { :host => "127.0.0.1" , :port => 26381 } ]
153+
154+ sentinel = {
155+ :sentinel => lambda do |command , *args |
156+ [ "127.0.0.1" , "6382" ]
157+ end
158+ }
159+
160+ master = {
161+ :role => lambda do
162+ [ "slave" ]
163+ end
164+ }
165+
166+ ex = assert_raise ( Redis ::ConnectionError ) do
167+ RedisMock . start ( master , { } , 6382 ) do
168+ RedisMock . start ( sentinel , { } , 26381 ) do
169+ redis = Redis . new ( :url => "redis://master1" , :sentinels => sentinels , :role => :master )
170+
171+ assert redis . ping
172+ end
173+ end
174+ end
175+
176+ assert_match /Instance role mismatch/ , ex . message
177+ end
150178end
You can’t perform that action at this time.
0 commit comments