Skip to content

Commit 418e872

Browse files
committed
Stabilize the sentinel suite
1 parent 2d8217a commit 418e872

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

test/helper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,20 @@ def build_slave_role_client(options = {})
239239

240240
private
241241

242+
def wait_for_quorum
243+
redis = build_sentinel_client
244+
50.times do
245+
if redis.sentinel('ckquorum', MASTER_NAME).start_with?('OK 3 usable Sentinels')
246+
return
247+
else
248+
sleep 0.1
249+
end
250+
rescue
251+
sleep 0.1
252+
end
253+
raise "ckquorum timeout"
254+
end
255+
242256
def _format_options(options = {})
243257
{
244258
url: "redis://#{MASTER_NAME}",

test/sentinel/sentinel_command_test.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class SentinelCommandsTest < Minitest::Test
77
include Helper::Sentinel
88

99
def test_sentinel_command_master
10+
wait_for_quorum
11+
1012
redis = build_sentinel_client
1113
result = redis.sentinel('master', MASTER_NAME)
1214

@@ -15,6 +17,8 @@ def test_sentinel_command_master
1517
end
1618

1719
def test_sentinel_command_masters
20+
wait_for_quorum
21+
1822
redis = build_sentinel_client
1923
result = redis.sentinel('masters')
2024

@@ -24,6 +28,8 @@ def test_sentinel_command_masters
2428
end
2529

2630
def test_sentinel_command_slaves
31+
wait_for_quorum
32+
2733
redis = build_sentinel_client
2834
result = redis.sentinel('slaves', MASTER_NAME)
2935

@@ -33,6 +39,8 @@ def test_sentinel_command_slaves
3339
end
3440

3541
def test_sentinel_command_sentinels
42+
wait_for_quorum
43+
3644
redis = build_sentinel_client
3745
result = redis.sentinel('sentinels', MASTER_NAME)
3846

@@ -51,9 +59,10 @@ def test_sentinel_command_get_master_by_name
5159
end
5260

5361
def test_sentinel_command_ckquorum
62+
wait_for_quorum
63+
5464
redis = build_sentinel_client
5565
result = redis.sentinel('ckquorum', MASTER_NAME)
56-
5766
assert_equal result, 'OK 3 usable Sentinels. Quorum and failover authorization can be reached'
5867
end
5968
end

test/sentinel/sentinel_test.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ class SentinelTest < Minitest::Test
66
include Helper::Sentinel
77

88
def test_sentinel_master_role_connection
9+
wait_for_quorum
10+
911
actual = redis.role
1012

1113
assert_equal 'master', actual[0]
12-
assert_equal SLAVE_PORT, actual[2][0][1]
1314
end
1415

1516
def test_sentinel_slave_role_connection
17+
wait_for_quorum
18+
1619
redis = build_slave_role_client
1720
actual = redis.role
1821

0 commit comments

Comments
 (0)