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