Skip to content

Commit bb67a53

Browse files
authored
Merge pull request #1192 from casperisfine/fix-sentinel-tests
Update sentinel tests for redis-client 0.14
2 parents 5904289 + 3c7a0e6 commit bb67a53

File tree

1 file changed

+98
-19
lines changed

1 file changed

+98
-19
lines changed

test/sentinel/sentinel_test.rb

Lines changed: 98 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ def test_sentinel_failover
7272
s2 = {
7373
sentinel: lambda do |command, *args|
7474
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
7683
end
7784
}
7885

@@ -87,7 +94,7 @@ def test_sentinel_failover
8794
end
8895

8996
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"]]
9198
end
9299

93100
def test_sentinel_failover_prioritize_healthy_sentinel
@@ -109,7 +116,17 @@ def test_sentinel_failover_prioritize_healthy_sentinel
109116
s2 = {
110117
sentinel: lambda do |command, *args|
111118
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
113130
end
114131
}
115132

@@ -128,7 +145,7 @@ def test_sentinel_failover_prioritize_healthy_sentinel
128145
end
129146

130147
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]
132149
end
133150

134151
def test_sentinel_with_non_sentinel_options
@@ -146,7 +163,17 @@ def test_sentinel_with_non_sentinel_options
146163
end,
147164
sentinel: lambda do |command, *args|
148165
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
150177
end
151178
}
152179
end
@@ -170,7 +197,7 @@ def test_sentinel_with_non_sentinel_options
170197
end
171198
end
172199

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]
174201
assert_equal [%w[auth foo], %w[role]], commands[:m1]
175202
end
176203

@@ -189,7 +216,17 @@ def test_authentication_for_sentinel
189216
end,
190217
sentinel: lambda do |command, *args|
191218
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
193230
end
194231
}
195232
end
@@ -213,7 +250,7 @@ def test_authentication_for_sentinel
213250
end
214251
end
215252

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]
217254
assert_equal [%w[role]], commands[:m1]
218255
end
219256

@@ -232,8 +269,18 @@ def test_authentication_for_sentinel_and_redis
232269
end,
233270
sentinel: lambda do |command, *args|
234271
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,
237284
}
238285
end
239286

@@ -245,7 +292,10 @@ def test_authentication_for_sentinel_and_redis
245292
role: lambda do
246293
commands[:m1] << ['role']
247294
['master']
248-
end
295+
end,
296+
sentinel: lambda do |command, *args|
297+
commands[:s2] << [command, *args]
298+
end,
249299
}
250300

251301
RedisMock.start(master) do |master_port|
@@ -256,7 +306,7 @@ def test_authentication_for_sentinel_and_redis
256306
end
257307
end
258308

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]
260310
assert_equal [%w[auth bar], %w[role]], commands[:m1]
261311
end
262312

@@ -275,7 +325,17 @@ def test_authentication_with_acl
275325
end,
276326
sentinel: lambda do |command, *args|
277327
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
279339
end
280340
}
281341
end
@@ -299,7 +359,7 @@ def test_authentication_with_acl
299359
end
300360
end
301361

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]
303363
assert_equal [%w[auth alice bar], %w[role]], commands[:m1]
304364
end
305365

@@ -308,8 +368,17 @@ def test_sentinel_role_mismatch
308368

309369
sentinel = lambda do |port|
310370
{
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
313382
end
314383
}
315384
end
@@ -342,13 +411,23 @@ def test_sentinel_retries
342411

343412
handler = lambda do |id, port|
344413
{
345-
sentinel: lambda do |_command, *_args|
414+
sentinel: lambda do |command, *_args|
346415
connections << id
347416

348417
if connections.count(id) < 2
349418
:close
350419
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
352431
end
353432
end
354433
}
@@ -372,7 +451,7 @@ def test_sentinel_retries
372451
end
373452
end
374453

375-
assert_equal %i[s1 s2 s1], connections
454+
assert_equal %i[s1 s2 s1 s1], connections
376455

377456
connections.clear
378457

0 commit comments

Comments
 (0)