33require 'testing_helper'
44
55class TestAgainstClusterBroken < TestingWrapper
6- WAIT_SEC = 3
6+ WAIT_SEC = 1
7+ MAX_ATTEMPTS = 60
8+ NUMBER_OF_KEYS = 10
79
810 def setup
911 @captured_commands = ::Middlewares ::CommandCapture ::CommandBuffer . new
@@ -24,23 +26,26 @@ def setup
2426 )
2527 @captured_commands . clear
2628 @redirect_count . clear
29+ @cluster_down_error_count = 0
2730 end
2831
2932 def teardown
3033 @client &.close
3134 @controller &.close
32- print "#{ @redirect_count . get } , ClusterNodesCall: #{ @captured_commands . count ( 'cluster' , 'nodes' ) } = "
35+ print "#{ @redirect_count . get } , " \
36+ "ClusterNodesCall: #{ @captured_commands . count ( 'cluster' , 'nodes' ) } , " \
37+ "ClusterDownError: #{ @cluster_down_error_count } = "
3338 end
3439
3540 def test_a_replica_is_down
3641 sacrifice = @controller . select_sacrifice_of_replica
37- do_test_a_node_is_down ( sacrifice , number_of_keys : 10 )
42+ do_test_a_node_is_down ( sacrifice , number_of_keys : NUMBER_OF_KEYS )
3843 refute ( @captured_commands . count ( 'cluster' , 'nodes' ) . zero? , @captured_commands . to_a . map ( &:command ) )
3944 end
4045
4146 def test_a_primary_is_down
4247 sacrifice = @controller . select_sacrifice_of_primary
43- do_test_a_node_is_down ( sacrifice , number_of_keys : 10 )
48+ do_test_a_node_is_down ( sacrifice , number_of_keys : NUMBER_OF_KEYS )
4449 refute ( @captured_commands . count ( 'cluster' , 'nodes' ) . zero? , @captured_commands . to_a . map ( &:command ) )
4550 end
4651
@@ -57,8 +62,8 @@ def wait_for_replication
5762 def do_test_a_node_is_down ( sacrifice , number_of_keys :)
5863 prepare_test_data ( number_of_keys : number_of_keys )
5964
60- kill_a_node ( sacrifice , kill_attempts : 10 )
61- wait_for_cluster_to_be_ready ( wait_attempts : 10 )
65+ kill_a_node ( sacrifice , kill_attempts : MAX_ATTEMPTS )
66+ wait_for_cluster_to_be_ready ( wait_attempts : MAX_ATTEMPTS )
6267
6368 assert_equal ( 'PONG' , @client . call ( 'PING' ) , 'Case: PING' )
6469 do_assertions_without_pipelining ( number_of_keys : number_of_keys )
@@ -75,15 +80,15 @@ def kill_a_node(sacrifice, kill_attempts:)
7580 refute_nil ( sacrifice , "#{ sacrifice . config . host } :#{ sacrifice . config . port } " )
7681
7782 loop do
78- break if kill_attempts <= 0
83+ raise MaxRetryExceeded if kill_attempts <= 0
7984
85+ kill_attempts -= 1
8086 sacrifice . call ( 'SHUTDOWN' , 'NOSAVE' )
8187 rescue ::RedisClient ::CommandError => e
8288 raise unless e . message . include? ( 'Errors trying to SHUTDOWN' )
8389 rescue ::RedisClient ::ConnectionError
8490 break
8591 ensure
86- kill_attempts -= 1
8792 sleep WAIT_SEC
8893 end
8994
@@ -92,11 +97,13 @@ def kill_a_node(sacrifice, kill_attempts:)
9297
9398 def wait_for_cluster_to_be_ready ( wait_attempts :)
9499 loop do
95- break if wait_attempts <= 0 || @client . call ( 'PING' ) == 'PONG'
100+ raise MaxRetryExceeded if wait_attempts <= 0
101+
102+ wait_attempts -= 1
103+ break if @client . call ( 'PING' ) == 'PONG'
96104 rescue ::RedisClient ::Cluster ::NodeMightBeDown
97- # ignore
105+ @cluster_down_error_count += 1
98106 ensure
99- wait_attempts -= 1
100107 sleep WAIT_SEC
101108 end
102109 end
0 commit comments