]>
Commit | Line | Data |
---|---|---|
8b654e54 | 1 | start_server {tags {"repl"}} { |
2 | start_server {} { | |
3 | test {First server should have role slave after SLAVEOF} { | |
4 | r -1 slaveof [srv 0 host] [srv 0 port] | |
5 | after 1000 | |
6 | s -1 role | |
7 | } {slave} | |
8 | ||
c1c9d551 | 9 | test {BRPOPLPUSH replication, when blocking against empty list} { |
10 | set rd [redis_deferring_client] | |
11 | $rd brpoplpush a b 5 | |
12 | r lpush a foo | |
28ccb530 | 13 | wait_for_condition 50 100 { |
14 | [r debug digest] eq [r -1 debug digest] | |
15 | } else { | |
16 | fail "Master and slave have different digest: [r debug digest] VS [r -1 debug digest]" | |
17 | } | |
c1c9d551 | 18 | } |
19 | ||
20 | test {BRPOPLPUSH replication, list exists} { | |
21 | set rd [redis_deferring_client] | |
22 | r lpush c 1 | |
23 | r lpush c 2 | |
24 | r lpush c 3 | |
25 | $rd brpoplpush c d 5 | |
26 | after 1000 | |
27 | assert_equal [r debug digest] [r -1 debug digest] | |
28 | } | |
8b654e54 | 29 | } |
30 | } | |
31 | ||
7f7499ee | 32 | start_server {tags {"repl"}} { |
85ecc65e PN |
33 | r set mykey foo |
34 | ||
9e5d2e8b | 35 | start_server {} { |
85ecc65e PN |
36 | test {Second server should have role master at first} { |
37 | s role | |
38 | } {master} | |
39 | ||
40 | test {SLAVEOF should start with link status "down"} { | |
41 | r slaveof [srv -1 host] [srv -1 port] | |
42 | s master_link_status | |
43 | } {down} | |
44 | ||
45 | test {The role should immediately be changed to "slave"} { | |
46 | s role | |
47 | } {slave} | |
48 | ||
49 | wait_for_sync r | |
50 | test {Sync should have transferred keys from master} { | |
51 | r get mykey | |
52 | } {foo} | |
53 | ||
54 | test {The link status should be up} { | |
55 | s master_link_status | |
56 | } {up} | |
57 | ||
58 | test {SET on the master should immediately propagate} { | |
59 | r -1 set mykey bar | |
4c378d7f | 60 | if {$::valgrind} {after 2000} |
85ecc65e PN |
61 | r 0 get mykey |
62 | } {bar} | |
c0875a77 | 63 | |
64 | test {FLUSHALL should replicate} { | |
65 | r -1 flushall | |
66 | if {$::valgrind} {after 2000} | |
67 | list [r -1 dbsize] [r 0 dbsize] | |
68 | } {0 0} | |
85ecc65e PN |
69 | } |
70 | } | |
414c3dea | 71 | |
72 | proc start_write_load {host port seconds} { | |
73 | exec tclsh8.5 tests/helpers/gen_write_load.tcl $host $port $seconds & | |
74 | } | |
75 | ||
76 | proc stop_write_load {handle} { | |
77 | catch {exec /bin/kill -9 $handle} | |
78 | } | |
79 | ||
80 | start_server {tags {"repl"}} { | |
81 | set master [srv 0 client] | |
82 | set master_host [srv 0 host] | |
83 | set master_port [srv 0 port] | |
84 | set slaves {} | |
85 | set load_handle0 [start_write_load $master_host $master_port 20] | |
86 | set load_handle1 [start_write_load $master_host $master_port 20] | |
87 | set load_handle2 [start_write_load $master_host $master_port 20] | |
88 | set load_handle3 [start_write_load $master_host $master_port 20] | |
89 | set load_handle4 [start_write_load $master_host $master_port 20] | |
90 | after 2000 | |
91 | start_server {} { | |
92 | lappend slaves [srv 0 client] | |
93 | start_server {} { | |
94 | lappend slaves [srv 0 client] | |
95 | start_server {} { | |
96 | lappend slaves [srv 0 client] | |
97 | test "Connect multiple slaves at the same time (issue #141)" { | |
98 | [lindex $slaves 0] slaveof $master_host $master_port | |
99 | [lindex $slaves 1] slaveof $master_host $master_port | |
100 | [lindex $slaves 2] slaveof $master_host $master_port | |
101 | ||
102 | # Wait for all the three slaves to reach the "online" state | |
459e2975 | 103 | set retry 500 |
414c3dea | 104 | while {$retry} { |
105 | set info [r -3 info] | |
106 | if {[string match {*slave0:*,online*slave1:*,online*slave2:*,online*} $info]} { | |
107 | break | |
108 | } else { | |
109 | incr retry -1 | |
110 | after 100 | |
111 | } | |
112 | } | |
113 | if {$retry == 0} { | |
114 | error "assertion:Slaves not correctly synchronized" | |
115 | } | |
116 | stop_write_load $load_handle0 | |
117 | stop_write_load $load_handle1 | |
118 | stop_write_load $load_handle2 | |
119 | stop_write_load $load_handle3 | |
120 | stop_write_load $load_handle4 | |
06312eed | 121 | set retry 10 |
122 | while {$retry && ([$master debug digest] ne [[lindex $slaves 0] debug digest])} { | |
123 | after 1000 | |
124 | incr retry -1 | |
125 | } | |
414c3dea | 126 | set digest [$master debug digest] |
127 | set digest0 [[lindex $slaves 0] debug digest] | |
128 | set digest1 [[lindex $slaves 1] debug digest] | |
129 | set digest2 [[lindex $slaves 2] debug digest] | |
130 | assert {$digest ne 0000000000000000000000000000000000000000} | |
131 | assert {$digest eq $digest0} | |
132 | assert {$digest eq $digest1} | |
133 | assert {$digest eq $digest2} | |
134 | #puts [$master dbsize] | |
135 | #puts [[lindex $slaves 0] dbsize] | |
136 | #puts [[lindex $slaves 1] dbsize] | |
137 | #puts [[lindex $slaves 2] dbsize] | |
138 | } | |
139 | } | |
140 | } | |
141 | } | |
142 | } |