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
} {
64 if {$::valgrind} {after 2000}
68 test
{FLUSHALL should replicate
} {
70 if {$::valgrind} {after 2000}
71 list [r
-1 dbsize
] [r
0 dbsize
]
76 proc start_write_load
{host port seconds
} {
77 exec tclsh8.5 tests
/helpers
/gen_write_load.tcl
$host $port $seconds &
80 proc stop_write_load
{handle
} {
81 catch {exec /bin
/kill
-9 $handle}
84 start_server
{tags
{"repl"}} {
85 set master
[srv
0 client
]
86 set master_host
[srv
0 host
]
87 set master_port
[srv
0 port
]
89 set load_handle0
[start_write_load
$master_host $master_port 3]
90 set load_handle1
[start_write_load
$master_host $master_port 5]
91 set load_handle2
[start_write_load
$master_host $master_port 20]
92 set load_handle3
[start_write_load
$master_host $master_port 8]
93 set load_handle4
[start_write_load
$master_host $master_port 4]
95 lappend slaves
[srv
0 client
]
97 lappend slaves
[srv
0 client
]
99 lappend slaves
[srv
0 client
]
100 test
"Connect multiple slaves at the same time (issue #141)" {
101 # Send SALVEOF commands to slaves
102 [lindex $slaves 0] slaveof
$master_host $master_port
103 [lindex $slaves 1] slaveof
$master_host $master_port
104 [lindex $slaves 2] slaveof
$master_host $master_port
106 # Wait for all the three slaves to reach the "online" state
110 if {[string match
{*slave0
:*,online
*slave1
:*,online
*slave2
:*,online
*} $info]} {
118 error "assertion:Slaves not correctly synchronized"
121 # Stop the write load
122 stop_write_load
$load_handle0
123 stop_write_load
$load_handle1
124 stop_write_load
$load_handle2
125 stop_write_load
$load_handle3
126 stop_write_load
$load_handle4
128 # Wait that slaves exit the "loading" state
129 wait_for_condition
500 100 {
130 ![string match
{*loading
:1*} [[lindex $slaves 0] info]] &&
131 ![string match
{*loading
:1*} [[lindex $slaves 1] info]] &&
132 ![string match
{*loading
:1*} [[lindex $slaves 2] info]]
134 fail
"Slaves still loading data after too much time"
137 # Make sure that slaves and master have same number of keys
138 wait_for_condition
500 100 {
139 [$master dbsize
] == [[lindex $slaves 0] dbsize
] &&
140 [$master dbsize
] == [[lindex $slaves 1] dbsize
] &&
141 [$master dbsize
] == [[lindex $slaves 2] dbsize
]
143 fail
"Different number of keys between masted and slave after too long time."
147 set digest
[$master debug digest
]
148 set digest0
[[lindex $slaves 0] debug digest
]
149 set digest1
[[lindex $slaves 1] debug digest
]
150 set digest2
[[lindex $slaves 2] debug digest
]
151 assert
{$digest ne
0000000000000000000000000000000000000000}
152 assert
{$digest eq
$digest0}
153 assert
{$digest eq
$digest1}
154 assert
{$digest eq
$digest2}