1source "../tests/includes/init-tests.tcl"
2
3proc cluster_allocate_mixedSlots {n} {
4    set slot 16383
5    while {$slot >= 0} {
6        set node [expr {$slot % $n}]
7        lappend slots_$node $slot
8        incr slot -1
9    }
10    for {set j 0} {$j < $n} {incr j} {
11        R $j cluster addslots {*}[set slots_${j}]
12    }
13}
14
15proc create_cluster_with_mixedSlot {masters slaves} {
16    cluster_allocate_mixedSlots $masters
17    if {$slaves} {
18        cluster_allocate_slaves $masters $slaves
19    }
20    assert_cluster_state ok
21}
22
23test "Create a 5 nodes cluster" {
24    create_cluster_with_mixedSlot 5 15
25}
26
27test "Cluster is up" {
28    assert_cluster_state ok
29}
30
31test "Cluster is writable" {
32    cluster_write_test 0
33}
34
35test "Instance #5 is a slave" {
36    assert {[RI 5 role] eq {slave}}
37}
38
39test "client do not break when cluster slot" {
40    R 0 config set client-output-buffer-limit "normal 33554432 16777216 60"
41    if { [catch {R 0 cluster slots}] } {
42        fail "output overflow when cluster slots"
43    }
44}
45
46test "client can handle keys with hash tag" {
47    set cluster [redis_cluster 127.0.0.1:[get_instance_attrib redis 0 port]]
48    $cluster set foo{tag} bar
49    $cluster close
50}
51
52if {$::tls} {
53    test {CLUSTER SLOTS from non-TLS client in TLS cluster} {
54        set slots_tls [R 0 cluster slots]
55        set host [get_instance_attrib redis 0 host]
56        set plaintext_port [get_instance_attrib redis 0 plaintext-port]
57        set client_plain [redis $host $plaintext_port 0 0]
58        set slots_plain [$client_plain cluster slots]
59        $client_plain close
60        # Compare the ports in the first row
61        assert_no_match [lindex $slots_tls 0 3 1] [lindex $slots_plain 0 3 1]
62    }
63}
64