1 start_server
{tags
{"repl"}} {
3 test
{First server should have role slave
after SLAVEOF
} {
4 r
-1 slaveof
[srv
0 host
] [srv
0 port
]
5 wait_for_condition
50 100 {
6 [s
-1 role
] eq
{slave
} &&
7 [string match
{*master_link_status
:up
*} [r
-1 info replication
]]
9 fail
"Can't turn the instance into a slave"
13 test
{BRPOPLPUSH replication
, when blocking against empty
list} {
14 set rd
[redis_deferring_client
]
17 wait_for_condition
50 100 {
18 [r debug digest
] eq
[r
-1 debug digest
]
20 fail
"Master and slave have different digest: [r debug digest] VS [r -1 debug digest]"
24 test
{BRPOPLPUSH replication
, list exists
} {
25 set rd
[redis_deferring_client
]
31 assert_equal
[r debug digest
] [r
-1 debug digest
]
36 start_server
{tags
{"repl"}} {
40 test
{Second server should have role master at first
} {
44 test
{SLAVEOF should start with link status
"down"} {
45 r slaveof
[srv
-1 host
] [srv
-1 port
]
49 test
{The role should immediately be changed to
"slave"} {
54 test
{Sync should have transferred keys from master
} {
58 test
{The link status should be up
} {
62 test
{SET on the master should immediately propagate
} {
65 wait_for_condition
500 100 {
66 [r
0 get mykey
] eq
{bar
}
68 fail
"SET on master did not propagated on slave"
72 test
{FLUSHALL should replicate
} {
74 if {$::valgrind} {after 2000}
75 list [r
-1 dbsize
] [r
0 dbsize
]
80 proc start_write_load
{host port seconds
} {
81 exec tclsh8.5 tests
/helpers
/gen_write_load.tcl
$host $port $seconds &
84 proc stop_write_load
{handle
} {
85 catch {exec /bin
/kill
-9 $handle}
88 start_server
{tags
{"repl"}} {
89 set master
[srv
0 client
]
90 set master_host
[srv
0 host
]
91 set master_port
[srv
0 port
]
93 set load_handle0
[start_write_load
$master_host $master_port 3]
94 set load_handle1
[start_write_load
$master_host $master_port 5]
95 set load_handle2
[start_write_load
$master_host $master_port 20]
96 set load_handle3
[start_write_load
$master_host $master_port 8]
97 set load_handle4
[start_write_load
$master_host $master_port 4]
99 lappend slaves
[srv
0 client
]
101 lappend slaves
[srv
0 client
]
103 lappend slaves
[srv
0 client
]
104 test
"Connect multiple slaves at the same time (issue #141)" {
105 # Send SALVEOF commands to slaves
106 [lindex $slaves 0] slaveof
$master_host $master_port
107 [lindex $slaves 1] slaveof
$master_host $master_port
108 [lindex $slaves 2] slaveof
$master_host $master_port
110 # Wait for all the three slaves to reach the "online" state
114 if {[string match
{*slave0
:*,online
*slave1
:*,online
*slave2
:*,online
*} $info]} {
122 error "assertion:Slaves not correctly synchronized"
125 # Stop the write load
126 stop_write_load
$load_handle0
127 stop_write_load
$load_handle1
128 stop_write_load
$load_handle2
129 stop_write_load
$load_handle3
130 stop_write_load
$load_handle4
132 # Wait that slaves exit the "loading" state
133 wait_for_condition
500 100 {
134 ![string match
{*loading
:1*} [[lindex $slaves 0] info]] &&
135 ![string match
{*loading
:1*} [[lindex $slaves 1] info]] &&
136 ![string match
{*loading
:1*} [[lindex $slaves 2] info]]
138 fail
"Slaves still loading data after too much time"
141 # Make sure that slaves and master have same number of keys
142 wait_for_condition
500 100 {
143 [$master dbsize
] == [[lindex $slaves 0] dbsize
] &&
144 [$master dbsize
] == [[lindex $slaves 1] dbsize
] &&
145 [$master dbsize
] == [[lindex $slaves 2] dbsize
]
147 fail
"Different number of keys between masted and slave after too long time."
151 set digest
[$master debug digest
]
152 set digest0
[[lindex $slaves 0] debug digest
]
153 set digest1
[[lindex $slaves 1] debug digest
]
154 set digest2
[[lindex $slaves 2] debug digest
]
155 assert
{$digest ne
0000000000000000000000000000000000000000}
156 assert
{$digest eq
$digest0}
157 assert
{$digest eq
$digest1}
158 assert
{$digest eq
$digest2}