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        catch {R $id flushall} ; # May fail for readonly slaves.
31        R $id MULTI
32        R $id cluster reset hard
33        R $id cluster set-config-epoch [expr {$id+1}]
34        R $id EXEC
35        R $id config set cluster-node-timeout 3000
36        R $id config set cluster-slave-validity-factor 10
37        R $id config rewrite
38    }
39}
40
41test "Cluster Join and auto-discovery test" {
42    # Join node 0 with 1, 1 with 2, ... and so forth.
43    # If auto-discovery works all nodes will know every other node
44    # eventually.
45    set ids {}
46    foreach_redis_id id {lappend ids $id}
47    for {set j 0} {$j < [expr [llength $ids]-1]} {incr j} {
48        set a [lindex $ids $j]
49        set b [lindex $ids [expr $j+1]]
50        set b_port [get_instance_attrib redis $b port]
51        R $a cluster meet 127.0.0.1 $b_port
52    }
53
54    foreach_redis_id id {
55        wait_for_condition 1000 50 {
56            [llength [get_cluster_nodes $id]] == [llength $ids]
57        } else {
58            fail "Cluster failed to join into a full mesh."
59        }
60    }
61}
62
63test "Before slots allocation, all nodes report cluster failure" {
64    assert_cluster_state fail
65}
66