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)
501
501
end
502
502
503
503
if role != @role
504
- disconnect
504
+ client . disconnect
505
505
raise ConnectionError , "Instance role mismatch. Expected #{ @role } , got #{ role } ."
506
506
end
507
507
end
Original file line number Diff line number Diff line change @@ -147,4 +147,32 @@ def test_sentinel_with_auth
147
147
assert_equal commands [ :s1 ] , [ %w[ get-master-addr-by-name master1 ] ]
148
148
assert_equal commands [ :m1 ] , [ %w[ auth foo ] , %w[ role ] ]
149
149
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
150
178
end
You can’t perform that action at this time.
0 commit comments