@@ -72,7 +72,14 @@ def test_sentinel_failover
72
72
s2 = {
73
73
sentinel : lambda do |command , *args |
74
74
commands [ :s2 ] << [ command , *args ]
75
- [ "127.0.0.1" , "6381" ]
75
+ case command
76
+ when "get-master-addr-by-name"
77
+ [ "127.0.0.1" , "6381" ]
78
+ when "sentinels"
79
+ [ ]
80
+ else
81
+ raise "Unexpected command #{ [ command , *args ] . inspect } "
82
+ end
76
83
end
77
84
}
78
85
@@ -87,7 +94,7 @@ def test_sentinel_failover
87
94
end
88
95
89
96
assert_equal commands [ :s1 ] , [ %w[ get-master-addr-by-name master1 ] ]
90
- assert_equal commands [ :s2 ] , [ %w[ get-master-addr-by-name master1 ] ]
97
+ assert_equal commands [ :s2 ] , [ %w[ get-master-addr-by-name master1 ] , [ "sentinels" , "master1" ] ]
91
98
end
92
99
93
100
def test_sentinel_failover_prioritize_healthy_sentinel
@@ -109,7 +116,17 @@ def test_sentinel_failover_prioritize_healthy_sentinel
109
116
s2 = {
110
117
sentinel : lambda do |command , *args |
111
118
commands [ :s2 ] << [ command , *args ]
112
- [ "127.0.0.1" , "6381" ]
119
+ case command
120
+ when "get-master-addr-by-name"
121
+ [ "127.0.0.1" , "6381" ]
122
+ when "sentinels"
123
+ [
124
+ [ "ip" , "127.0.0.1" , "port" , "26381" ] ,
125
+ [ "ip" , "127.0.0.1" , "port" , "26382" ] ,
126
+ ]
127
+ else
128
+ raise "Unexpected command #{ [ command , *args ] . inspect } "
129
+ end
113
130
end
114
131
}
115
132
@@ -128,7 +145,7 @@ def test_sentinel_failover_prioritize_healthy_sentinel
128
145
end
129
146
130
147
assert_equal [ %w[ get-master-addr-by-name master1 ] ] , commands [ :s1 ]
131
- assert_equal [ %w[ get-master-addr-by-name master1 ] ] , commands [ :s2 ]
148
+ assert_equal [ %w[ get-master-addr-by-name master1 ] , [ "sentinels" , "master1" ] ] , commands [ :s2 ]
132
149
end
133
150
134
151
def test_sentinel_with_non_sentinel_options
@@ -146,7 +163,17 @@ def test_sentinel_with_non_sentinel_options
146
163
end ,
147
164
sentinel : lambda do |command , *args |
148
165
commands [ :s1 ] << [ command , *args ]
149
- [ '127.0.0.1' , port . to_s ]
166
+ case command
167
+ when "get-master-addr-by-name"
168
+ [ "127.0.0.1" , port . to_s ]
169
+ when "sentinels"
170
+ [
171
+ [ "ip" , "127.0.0.1" , "port" , "26381" ] ,
172
+ [ "ip" , "127.0.0.1" , "port" , "26382" ] ,
173
+ ]
174
+ else
175
+ raise "Unexpected command #{ [ command , *args ] . inspect } "
176
+ end
150
177
end
151
178
}
152
179
end
@@ -170,7 +197,7 @@ def test_sentinel_with_non_sentinel_options
170
197
end
171
198
end
172
199
173
- assert_equal [ %w[ get-master-addr-by-name master1 ] ] , commands [ :s1 ]
200
+ assert_equal [ %w[ get-master-addr-by-name master1 ] , [ "sentinels" , "master1" ] ] , commands [ :s1 ]
174
201
assert_equal [ %w[ auth foo ] , %w[ role ] ] , commands [ :m1 ]
175
202
end
176
203
@@ -189,7 +216,17 @@ def test_authentication_for_sentinel
189
216
end ,
190
217
sentinel : lambda do |command , *args |
191
218
commands [ :s1 ] << [ command , *args ]
192
- [ '127.0.0.1' , port . to_s ]
219
+ case command
220
+ when "get-master-addr-by-name"
221
+ [ "127.0.0.1" , port . to_s ]
222
+ when "sentinels"
223
+ [
224
+ [ "ip" , "127.0.0.1" , "port" , "26381" ] ,
225
+ [ "ip" , "127.0.0.1" , "port" , "26382" ] ,
226
+ ]
227
+ else
228
+ raise "Unexpected command #{ [ command , *args ] . inspect } "
229
+ end
193
230
end
194
231
}
195
232
end
@@ -213,7 +250,7 @@ def test_authentication_for_sentinel
213
250
end
214
251
end
215
252
216
- assert_equal [ %w[ auth foo ] , %w[ get-master-addr-by-name master1 ] ] , commands [ :s1 ]
253
+ assert_equal [ %w[ auth foo ] , %w[ get-master-addr-by-name master1 ] , [ "sentinels" , "master1" ] ] , commands [ :s1 ]
217
254
assert_equal [ %w[ role ] ] , commands [ :m1 ]
218
255
end
219
256
@@ -232,8 +269,18 @@ def test_authentication_for_sentinel_and_redis
232
269
end ,
233
270
sentinel : lambda do |command , *args |
234
271
commands [ :s1 ] << [ command , *args ]
235
- [ '127.0.0.1' , port . to_s ]
236
- end
272
+ case command
273
+ when "get-master-addr-by-name"
274
+ [ "127.0.0.1" , port . to_s ]
275
+ when "sentinels"
276
+ [
277
+ [ "ip" , "127.0.0.1" , "port" , "26381" ] ,
278
+ [ "ip" , "127.0.0.1" , "port" , "26382" ] ,
279
+ ]
280
+ else
281
+ raise "Unexpected command #{ [ command , *args ] . inspect } "
282
+ end
283
+ end ,
237
284
}
238
285
end
239
286
@@ -245,7 +292,10 @@ def test_authentication_for_sentinel_and_redis
245
292
role : lambda do
246
293
commands [ :m1 ] << [ 'role' ]
247
294
[ 'master' ]
248
- end
295
+ end ,
296
+ sentinel : lambda do |command , *args |
297
+ commands [ :s2 ] << [ command , *args ]
298
+ end ,
249
299
}
250
300
251
301
RedisMock . start ( master ) do |master_port |
@@ -256,7 +306,7 @@ def test_authentication_for_sentinel_and_redis
256
306
end
257
307
end
258
308
259
- assert_equal [ %w[ auth foo ] , %w[ get-master-addr-by-name master1 ] ] , commands [ :s1 ]
309
+ assert_equal [ %w[ auth foo ] , %w[ get-master-addr-by-name master1 ] , [ "sentinels" , "master1" ] ] , commands [ :s1 ]
260
310
assert_equal [ %w[ auth bar ] , %w[ role ] ] , commands [ :m1 ]
261
311
end
262
312
@@ -275,7 +325,17 @@ def test_authentication_with_acl
275
325
end ,
276
326
sentinel : lambda do |command , *args |
277
327
commands [ :s1 ] << [ command , *args ]
278
- [ '127.0.0.1' , port . to_s ]
328
+ case command
329
+ when "get-master-addr-by-name"
330
+ [ "127.0.0.1" , port . to_s ]
331
+ when "sentinels"
332
+ [
333
+ [ "ip" , "127.0.0.1" , "port" , "26381" ] ,
334
+ [ "ip" , "127.0.0.1" , "port" , "26382" ] ,
335
+ ]
336
+ else
337
+ raise "Unexpected command #{ [ command , *args ] . inspect } "
338
+ end
279
339
end
280
340
}
281
341
end
@@ -299,7 +359,7 @@ def test_authentication_with_acl
299
359
end
300
360
end
301
361
302
- assert_equal [ %w[ auth bob foo ] , %w[ get-master-addr-by-name master1 ] ] , commands [ :s1 ]
362
+ assert_equal [ %w[ auth bob foo ] , %w[ get-master-addr-by-name master1 ] , [ "sentinels" , "master1" ] ] , commands [ :s1 ]
303
363
assert_equal [ %w[ auth alice bar ] , %w[ role ] ] , commands [ :m1 ]
304
364
end
305
365
@@ -308,8 +368,17 @@ def test_sentinel_role_mismatch
308
368
309
369
sentinel = lambda do |port |
310
370
{
311
- sentinel : lambda do |_command , *_args |
312
- [ "127.0.0.1" , port . to_s ]
371
+ sentinel : lambda do |command , *_args |
372
+ case command
373
+ when "get-master-addr-by-name"
374
+ [ "127.0.0.1" , port . to_s ]
375
+ when "sentinels"
376
+ [
377
+ [ "ip" , "127.0.0.1" , "port" , "26381" ] ,
378
+ ]
379
+ else
380
+ raise "Unexpected command #{ [ command , *args ] . inspect } "
381
+ end
313
382
end
314
383
}
315
384
end
@@ -342,13 +411,23 @@ def test_sentinel_retries
342
411
343
412
handler = lambda do |id , port |
344
413
{
345
- sentinel : lambda do |_command , *_args |
414
+ sentinel : lambda do |command , *_args |
346
415
connections << id
347
416
348
417
if connections . count ( id ) < 2
349
418
:close
350
419
else
351
- [ "127.0.0.1" , port . to_s ]
420
+ case command
421
+ when "get-master-addr-by-name"
422
+ [ "127.0.0.1" , port . to_s ]
423
+ when "sentinels"
424
+ [
425
+ [ "ip" , "127.0.0.1" , "port" , "26381" ] ,
426
+ [ "ip" , "127.0.0.1" , "port" , "26382" ] ,
427
+ ]
428
+ else
429
+ raise "Unexpected command #{ [ command , *args ] . inspect } "
430
+ end
352
431
end
353
432
end
354
433
}
@@ -372,7 +451,7 @@ def test_sentinel_retries
372
451
end
373
452
end
374
453
375
- assert_equal %i[ s1 s2 s1 ] , connections
454
+ assert_equal %i[ s1 s2 s1 s1 ] , connections
376
455
377
456
connections . clear
378
457
0 commit comments