]> git.saurik.com Git - redis.git/blob - tests/unit/aofrw.tcl
Safer handling of MULTI/EXEC on errors.
[redis.git] / tests / unit / aofrw.tcl
1 start_server {tags {"aofrw"}} {
2
3 test {Turning off AOF kills the background writing child if any} {
4 r config set appendonly yes
5 waitForBgrewriteaof r
6 r multi
7 r bgrewriteaof
8 r config set appendonly no
9 r exec
10 wait_for_condition 50 100 {
11 [string match {*Killing*AOF*child*} [exec tail -n5 < [srv 0 stdout]]]
12 } else {
13 fail "Can't find 'Killing AOF child' into recent logs"
14 }
15 }
16
17 foreach d {string int} {
18 foreach e {ziplist linkedlist} {
19 test "AOF rewrite of list with $e encoding, $d data" {
20 r flushall
21 if {$e eq {ziplist}} {set len 10} else {set len 1000}
22 for {set j 0} {$j < $len} {incr j} {
23 if {$d eq {string}} {
24 set data [randstring 0 16 alpha]
25 } else {
26 set data [randomInt 4000000000]
27 }
28 r lpush key $data
29 }
30 assert_equal [r object encoding key] $e
31 set d1 [r debug digest]
32 r bgrewriteaof
33 waitForBgrewriteaof r
34 r debug loadaof
35 set d2 [r debug digest]
36 if {$d1 ne $d2} {
37 error "assertion:$d1 is not equal to $d2"
38 }
39 }
40 }
41 }
42
43 foreach d {string int} {
44 foreach e {intset hashtable} {
45 test "AOF rewrite of set with $e encoding, $d data" {
46 r flushall
47 if {$e eq {intset}} {set len 10} else {set len 1000}
48 for {set j 0} {$j < $len} {incr j} {
49 if {$d eq {string}} {
50 set data [randstring 0 16 alpha]
51 } else {
52 set data [randomInt 4000000000]
53 }
54 r sadd key $data
55 }
56 if {$d ne {string}} {
57 assert_equal [r object encoding key] $e
58 }
59 set d1 [r debug digest]
60 r bgrewriteaof
61 waitForBgrewriteaof r
62 r debug loadaof
63 set d2 [r debug digest]
64 if {$d1 ne $d2} {
65 error "assertion:$d1 is not equal to $d2"
66 }
67 }
68 }
69 }
70
71 foreach d {string int} {
72 foreach e {ziplist hashtable} {
73 test "AOF rewrite of hash with $e encoding, $d data" {
74 r flushall
75 if {$e eq {ziplist}} {set len 10} else {set len 1000}
76 for {set j 0} {$j < $len} {incr j} {
77 if {$d eq {string}} {
78 set data [randstring 0 16 alpha]
79 } else {
80 set data [randomInt 4000000000]
81 }
82 r hset key $data $data
83 }
84 assert_equal [r object encoding key] $e
85 set d1 [r debug digest]
86 r bgrewriteaof
87 waitForBgrewriteaof r
88 r debug loadaof
89 set d2 [r debug digest]
90 if {$d1 ne $d2} {
91 error "assertion:$d1 is not equal to $d2"
92 }
93 }
94 }
95 }
96
97 foreach d {string int} {
98 foreach e {ziplist skiplist} {
99 test "AOF rewrite of zset with $e encoding, $d data" {
100 r flushall
101 if {$e eq {ziplist}} {set len 10} else {set len 1000}
102 for {set j 0} {$j < $len} {incr j} {
103 if {$d eq {string}} {
104 set data [randstring 0 16 alpha]
105 } else {
106 set data [randomInt 4000000000]
107 }
108 r zadd key [expr rand()] $data
109 }
110 assert_equal [r object encoding key] $e
111 set d1 [r debug digest]
112 r bgrewriteaof
113 waitForBgrewriteaof r
114 r debug loadaof
115 set d2 [r debug digest]
116 if {$d1 ne $d2} {
117 error "assertion:$d1 is not equal to $d2"
118 }
119 }
120 }
121 }
122
123 test {BGREWRITEAOF is delayed if BGSAVE is in progress} {
124 r multi
125 r bgsave
126 r bgrewriteaof
127 r info persistence
128 set res [r exec]
129 assert_match {*scheduled*} [lindex $res 1]
130 assert_match {*aof_rewrite_scheduled:1*} [lindex $res 2]
131 while {[string match {*aof_rewrite_scheduled:1*} [r info persistence]]} {
132 after 100
133 }
134 }
135
136 test {BGREWRITEAOF is refused if already in progress} {
137 catch {
138 r multi
139 r bgrewriteaof
140 r bgrewriteaof
141 r exec
142 } e
143 assert_match {*ERR*already*} $e
144 while {[string match {*aof_rewrite_scheduled:1*} [r info persistence]]} {
145 after 100
146 }
147 }
148 }