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