]> git.saurik.com Git - redis.git/blame - tests/test_helper.tcl
replication asynchronous SYNC information in INFO output
[redis.git] / tests / test_helper.tcl
CommitLineData
98578b57
PN
1# Redis test suite. Copyright (C) 2009 Salvatore Sanfilippo antirez@gmail.com
2# This softare is released under the BSD License. See the COPYING file for
3# more information.
4
5set tcl_precision 17
ab72b483 6source tests/support/redis.tcl
7source tests/support/server.tcl
8source tests/support/tmpfile.tcl
9source tests/support/test.tcl
10source tests/support/util.tcl
98578b57
PN
11
12set ::host 127.0.0.1
47bebf15 13set ::port 16379
e59a64b8 14set ::traceleaks 0
c4669d25 15set ::valgrind 0
6e0e5bed
PN
16set ::denytags {}
17set ::allowtags {}
7d04fc75 18set ::external 0; # If "1" this means, we are running against external instance
9f1ae9ab 19set ::file ""; # If set, runs only the tests in this comma separated list
98578b57
PN
20
21proc execute_tests name {
ab72b483 22 source "tests/$name.tcl"
98578b57
PN
23}
24
1c4114be
PN
25# Setup a list to hold a stack of server configs. When calls to start_server
26# are nested, use "srv 0 pid" to get the pid of the inner server. To access
27# outer servers, use "srv -1 pid" etcetera.
28set ::servers {}
f2dd4769
PN
29proc srv {args} {
30 set level 0
31 if {[string is integer [lindex $args 0]]} {
32 set level [lindex $args 0]
33 set property [lindex $args 1]
34 } else {
35 set property [lindex $args 0]
36 }
1c4114be
PN
37 set srv [lindex $::servers end+$level]
38 dict get $srv $property
39}
40
41# Provide easy access to the client for the inner server. It's possible to
42# prepend the argument list with a negative level to access clients for
43# servers running in outer blocks.
98578b57 44proc r {args} {
1c4114be
PN
45 set level 0
46 if {[string is integer [lindex $args 0]]} {
47 set level [lindex $args 0]
48 set args [lrange $args 1 end]
49 }
50 [srv $level "client"] {*}$args
51}
52
941c9fa2
PN
53proc reconnect {args} {
54 set level [lindex $args 0]
55 if {[string length $level] == 0 || ![string is integer $level]} {
56 set level 0
57 }
58
59 set srv [lindex $::servers end+$level]
60 set host [dict get $srv "host"]
61 set port [dict get $srv "port"]
62 set config [dict get $srv "config"]
63 set client [redis $host $port]
64 dict set srv "client" $client
65
66 # select the right db when we don't have to authenticate
67 if {![dict exists $config "requirepass"]} {
68 $client select 9
69 }
70
71 # re-set $srv in the servers list
72 set ::servers [lreplace $::servers end+$level 1 $srv]
73}
74
5eedc9c6
PN
75proc redis_deferring_client {args} {
76 set level 0
77 if {[llength $args] > 0 && [string is integer [lindex $args 0]]} {
78 set level [lindex $args 0]
79 set args [lrange $args 1 end]
80 }
81
82 # create client that defers reading reply
83 set client [redis [srv $level "host"] [srv $level "port"] 1]
84
85 # select the right db and read the response (OK)
86 $client select 9
87 $client read
88 return $client
89}
90
1c4114be
PN
91# Provide easy access to INFO properties. Same semantic as "proc r".
92proc s {args} {
93 set level 0
94 if {[string is integer [lindex $args 0]]} {
95 set level [lindex $args 0]
96 set args [lrange $args 1 end]
97 }
98 status [srv $level "client"] [lindex $args 0]
98578b57
PN
99}
100
f166bb1d 101proc cleanup {} {
c4669d25 102 catch {exec rm -rf {*}[glob tests/tmp/redis.conf.*]}
103 catch {exec rm -rf {*}[glob tests/tmp/server.*]}
f166bb1d
PN
104}
105
9f1ae9ab 106proc execute_everything {} {
98578b57
PN
107 execute_tests "unit/auth"
108 execute_tests "unit/protocol"
109 execute_tests "unit/basic"
110 execute_tests "unit/type/list"
111 execute_tests "unit/type/set"
112 execute_tests "unit/type/zset"
113 execute_tests "unit/type/hash"
114 execute_tests "unit/sort"
115 execute_tests "unit/expire"
116 execute_tests "unit/other"
c20c189d 117 execute_tests "unit/cas"
5a4f9f27 118 execute_tests "unit/quit"
85ecc65e 119 execute_tests "integration/replication"
53cbf66c 120 execute_tests "integration/aof"
588cd980 121# execute_tests "integration/redis-cli"
4589a823 122 execute_tests "unit/pubsub"
f166bb1d
PN
123
124 # run tests with VM enabled
d4507ec6 125 set ::global_overrides {vm-enabled yes}
f166bb1d
PN
126 execute_tests "unit/protocol"
127 execute_tests "unit/basic"
128 execute_tests "unit/type/list"
129 execute_tests "unit/type/set"
130 execute_tests "unit/type/zset"
131 execute_tests "unit/type/hash"
132 execute_tests "unit/sort"
133 execute_tests "unit/expire"
134 execute_tests "unit/other"
c20c189d 135 execute_tests "unit/cas"
9f1ae9ab
PN
136}
137
138proc main {} {
139 cleanup
140
141 if {[string length $::file] > 0} {
142 foreach {file} [split $::file ,] {
143 execute_tests $file
144 }
145 } else {
146 execute_everything
147 }
e39c8b50
PN
148
149 cleanup
98578b57
PN
150 puts "\n[expr $::passed+$::failed] tests, $::passed passed, $::failed failed"
151 if {$::failed > 0} {
152 puts "\n*** WARNING!!! $::failed FAILED TESTS ***\n"
e39c8b50 153 exit 1
98578b57 154 }
98578b57
PN
155}
156
73bd6c58
PN
157# parse arguments
158for {set j 0} {$j < [llength $argv]} {incr j} {
159 set opt [lindex $argv $j]
160 set arg [lindex $argv [expr $j+1]]
161 if {$opt eq {--tags}} {
162 foreach tag $arg {
163 if {[string index $tag 0] eq "-"} {
164 lappend ::denytags [string range $tag 1 end]
165 } else {
166 lappend ::allowtags $tag
167 }
168 }
169 incr j
9f1ae9ab
PN
170 } elseif {$opt eq {--file}} {
171 set ::file $arg
172 incr j
7d04fc75 173 } elseif {$opt eq {--host}} {
174 set ::external 1
175 set ::host $arg
176 incr j
177 } elseif {$opt eq {--port}} {
178 set ::port $arg
179 incr j
73bd6c58
PN
180 } else {
181 puts "Wrong argument: $opt"
182 exit 1
183 }
184}
185
436f18b6
PN
186if {[catch { main } err]} {
187 if {[string length $err] > 0} {
188 # only display error when not generated by the test suite
189 if {$err ne "exception"} {
190 puts $err
191 }
192 exit 1
193 }
194}