1# Initialization tests -- most units will start including this. 2 3test "(init) Restart killed instances" { 4 foreach type {redis} { 5 foreach_${type}_id id { 6 if {[get_instance_attrib $type $id pid] == -1} { 7 puts -nonewline "$type/$id " 8 flush stdout 9 restart_instance $type $id 10 } 11 } 12 } 13} 14 15test "Cluster nodes are reachable" { 16 foreach_redis_id id { 17 # Every node should be reachable. 18 wait_for_condition 1000 50 { 19 ([catch {R $id ping} ping_reply] == 0) && 20 ($ping_reply eq {PONG}) 21 } else { 22 catch {R $id ping} err 23 fail "Node #$id keeps replying '$err' to PING." 24 } 25 } 26} 27 28test "Cluster nodes hard reset" { 29 foreach_redis_id id { 30 if {$::valgrind} { 31 set node_timeout 10000 32 } else { 33 set node_timeout 3000 34 } 35 catch {R $id flushall} ; # May fail for readonly slaves. 36 R $id MULTI 37 R $id cluster reset hard 38 R $id cluster set-config-epoch [expr {$id+1}] 39 R $id EXEC 40 R $id config set cluster-node-timeout $node_timeout 41 R $id config set cluster-slave-validity-factor 10 42 R $id config rewrite 43 } 44} 45 46test "Cluster Join and auto-discovery test" { 47 # Join node 0 with 1, 1 with 2, ... and so forth. 48 # If auto-discovery works all nodes will know every other node 49 # eventually. 50 set ids {} 51 foreach_redis_id id {lappend ids $id} 52 for {set j 0} {$j < [expr [llength $ids]-1]} {incr j} { 53 set a [lindex $ids $j] 54 set b [lindex $ids [expr $j+1]] 55 set b_port [get_instance_attrib redis $b port] 56 R $a cluster meet 127.0.0.1 $b_port 57 } 58 59 foreach_redis_id id { 60 wait_for_condition 1000 50 { 61 [llength [get_cluster_nodes $id]] == [llength $ids] 62 } else { 63 fail "Cluster failed to join into a full mesh." 64 } 65 } 66} 67 68test "Before slots allocation, all nodes report cluster failure" { 69 assert_cluster_state fail 70} 71