aboutsummaryrefslogtreecommitdiff
path: root/examples/redis-unstable/tests/unit/moduleapi/cluster.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'examples/redis-unstable/tests/unit/moduleapi/cluster.tcl')
-rw-r--r--examples/redis-unstable/tests/unit/moduleapi/cluster.tcl227
1 files changed, 0 insertions, 227 deletions
diff --git a/examples/redis-unstable/tests/unit/moduleapi/cluster.tcl b/examples/redis-unstable/tests/unit/moduleapi/cluster.tcl
deleted file mode 100644
index 7141fe1..0000000
--- a/examples/redis-unstable/tests/unit/moduleapi/cluster.tcl
+++ /dev/null
@@ -1,227 +0,0 @@
1# Primitive tests on cluster-enabled redis with modules
2
3source tests/support/cli.tcl
4
5# cluster creation is complicated with TLS, and the current tests don't really need that coverage
6tags {tls:skip external:skip cluster modules} {
7
8set testmodule_nokey [file normalize tests/modules/blockonbackground.so]
9set testmodule_blockedclient [file normalize tests/modules/blockedclient.so]
10set testmodule [file normalize tests/modules/blockonkeys.so]
11
12set modules [list loadmodule $testmodule loadmodule $testmodule_nokey loadmodule $testmodule_blockedclient]
13start_cluster 3 0 [list tags {external:skip cluster modules} config_lines $modules] {
14
15 set node1 [srv 0 client]
16 set node2 [srv -1 client]
17 set node3 [srv -2 client]
18 set node3_pid [srv -2 pid]
19
20 test "Run blocking command (blocked on key) on cluster node3" {
21 # key9184688 is mapped to slot 10923 (first slot of node 3)
22 set node3_rd [redis_deferring_client -2]
23 $node3_rd fsl.bpop key9184688 0
24 $node3_rd flush
25 wait_for_condition 50 100 {
26 [s -2 blocked_clients] eq {1}
27 } else {
28 fail "Client executing blocking command (blocked on key) not blocked"
29 }
30 }
31
32 test "Run blocking command (no keys) on cluster node2" {
33 set node2_rd [redis_deferring_client -1]
34 $node2_rd block.block 0
35 $node2_rd flush
36
37 wait_for_condition 50 100 {
38 [s -1 blocked_clients] eq {1}
39 } else {
40 fail "Client executing blocking command (no keys) not blocked"
41 }
42 }
43
44
45 test "Perform a Resharding" {
46 exec src/redis-cli --cluster-yes --cluster reshard 127.0.0.1:[srv -2 port] \
47 --cluster-to [$node1 cluster myid] \
48 --cluster-from [$node3 cluster myid] \
49 --cluster-slots 1
50 }
51
52 test "Verify command (no keys) is unaffected after resharding" {
53 # verify there are blocked clients on node2
54 assert_equal [s -1 blocked_clients] {1}
55
56 #release client
57 $node2 block.release 0
58 }
59
60 test "Verify command (blocked on key) got unblocked after resharding" {
61 # this (read) will wait for the node3 to realize the new topology
62 assert_error {*MOVED*} {$node3_rd read}
63
64 # verify there are no blocked clients
65 assert_equal [s 0 blocked_clients] {0}
66 assert_equal [s -1 blocked_clients] {0}
67 assert_equal [s -2 blocked_clients] {0}
68 }
69
70 test "Wait for cluster to be stable" {
71 wait_for_condition 1000 50 {
72 [catch {exec src/redis-cli --cluster check 127.0.0.1:[srv 0 port]}] == 0 &&
73 [catch {exec src/redis-cli --cluster check 127.0.0.1:[srv -1 port]}] == 0 &&
74 [catch {exec src/redis-cli --cluster check 127.0.0.1:[srv -2 port]}] == 0 &&
75 [CI 0 cluster_state] eq {ok} &&
76 [CI 1 cluster_state] eq {ok} &&
77 [CI 2 cluster_state] eq {ok}
78 } else {
79 fail "Cluster doesn't stabilize"
80 }
81 }
82
83 test "Sanity test push cmd after resharding" {
84 assert_error {*MOVED*} {$node3 fsl.push key9184688 1}
85
86 set node1_rd [redis_deferring_client 0]
87 $node1_rd fsl.bpop key9184688 0
88 $node1_rd flush
89
90 wait_for_condition 50 100 {
91 [s 0 blocked_clients] eq {1}
92 } else {
93 puts "Client not blocked"
94 puts "read from blocked client: [$node1_rd read]"
95 fail "Client not blocked"
96 }
97
98 $node1 fsl.push key9184688 2
99 assert_equal {2} [$node1_rd read]
100 }
101
102 $node1_rd close
103 $node2_rd close
104 $node3_rd close
105
106 test "Run blocking command (blocked on key) again on cluster node1" {
107 $node1 del key9184688
108 # key9184688 is mapped to slot 10923 which has been moved to node1
109 set node1_rd [redis_deferring_client 0]
110 $node1_rd fsl.bpop key9184688 0
111 $node1_rd flush
112
113 wait_for_condition 50 100 {
114 [s 0 blocked_clients] eq {1}
115 } else {
116 fail "Client executing blocking command (blocked on key) again not blocked"
117 }
118 }
119
120 test "Run blocking command (no keys) again on cluster node2" {
121 set node2_rd [redis_deferring_client -1]
122
123 $node2_rd block.block 0
124 $node2_rd flush
125
126 wait_for_condition 50 100 {
127 [s -1 blocked_clients] eq {1}
128 } else {
129 fail "Client executing blocking command (no keys) again not blocked"
130 }
131 }
132
133 test "Kill a cluster node and wait for fail state" {
134 # kill node3 in cluster
135 pause_process $node3_pid
136
137 wait_for_condition 1000 50 {
138 [CI 0 cluster_state] eq {fail} &&
139 [CI 1 cluster_state] eq {fail}
140 } else {
141 fail "Cluster doesn't fail"
142 }
143 }
144
145 test "Verify command (blocked on key) got unblocked after cluster failure" {
146 assert_error {*CLUSTERDOWN*} {$node1_rd read}
147 }
148
149 test "Verify command (no keys) got unblocked after cluster failure" {
150 assert_error {*CLUSTERDOWN*} {$node2_rd read}
151
152 # verify there are no blocked clients
153 assert_equal [s 0 blocked_clients] {0}
154 assert_equal [s -1 blocked_clients] {0}
155 }
156
157 test "Verify command RM_Call is rejected when cluster is down" {
158 assert_error "ERR Can not execute a command 'set' while the cluster is down" {$node1 do_rm_call set x 1}
159 }
160
161 resume_process $node3_pid
162 $node1_rd close
163 $node2_rd close
164}
165
166set testmodule_keyspace_events [file normalize tests/modules/keyspace_events.so]
167set testmodule_postnotifications "[file normalize tests/modules/postnotifications.so] with_key_events"
168set modules [list loadmodule $testmodule_keyspace_events loadmodule $testmodule_postnotifications]
169start_cluster 2 2 [list tags {external:skip cluster modules} config_lines $modules] {
170
171 set master1 [srv 0 client]
172 set master2 [srv -1 client]
173 set replica1 [srv -2 client]
174 set replica2 [srv -3 client]
175
176 test "Verify keys deletion and notification effects happened on cluster slots change are replicated inside multi exec" {
177 $master2 set count_dels_{4oi} 1
178 $master2 del count_dels_{4oi}
179 assert_equal 1 [$master2 keyspace.get_dels]
180 wait_for_ofs_sync $master2 $replica2
181 assert_equal 1 [$replica2 keyspace.get_dels]
182 $master2 set count_dels_{4oi} 1
183
184 set repl [attach_to_replication_stream_on_connection -3]
185
186 $master1 cluster bumpepoch
187 $master1 cluster setslot 16382 node [$master1 cluster myid]
188
189 wait_for_cluster_propagation
190 wait_for_condition 50 100 {
191 [$master2 keyspace.get_dels] eq 2
192 } else {
193 fail "master did not delete the key"
194 }
195 wait_for_condition 50 100 {
196 [$replica2 keyspace.get_dels] eq 2
197 } else {
198 fail "replica did not increase del counter"
199 }
200
201 # the {lpush before_deleted count_dels_{4oi}} is a post notification job registered when 'count_dels_{4oi}' was removed
202 assert_replication_stream $repl {
203 {multi}
204 {del count_dels_{4oi}}
205 {keyspace.incr_dels}
206 {lpush before_deleted count_dels_{4oi}}
207 {exec}
208 }
209 close_replication_stream $repl
210 }
211}
212
213}
214
215set testmodule [file normalize tests/modules/basics.so]
216set modules [list loadmodule $testmodule]
217start_cluster 3 0 [list tags {external:skip cluster modules} config_lines $modules] {
218 set node1 [srv 0 client]
219 set node2 [srv -1 client]
220 set node3 [srv -2 client]
221
222 test "Verify RM_Call inside module load function on cluster mode" {
223 assert_equal {PONG} [$node1 PING]
224 assert_equal {PONG} [$node2 PING]
225 assert_equal {PONG} [$node3 PING]
226 }
227}