1 proc randstring
{min max
{type
binary}} {
2 set len
[expr {$min+int
(rand
()*($max-$min+1))}]
4 if {$type eq
{binary}} {
7 } elseif
{$type eq
{alpha
}} {
10 } elseif
{$type eq
{compr
}} {
15 append output
[format "%c" [expr {$minval+int
(rand
()*($maxval-$minval+1))}]]
21 # Useful for some test
22 proc zlistAlikeSort
{a b
} {
23 if {[lindex $a 0] > [lindex $b 0]} {return 1}
24 if {[lindex $a 0] < [lindex $b 0]} {return -1}
25 string compare
[lindex $a 1] [lindex $b 1]
28 # Return all log lines starting with the first line that contains a warning.
29 # Generally, this will be an assertion error with a stack trace.
30 proc warnings_from_file
{filename} {
31 set lines
[split [exec cat
$filename] "\n"]
35 if {[regexp {^
\[\d
+\]\s
+\d
+\s
+\w
+\s
+\d
{2}:\d
{2}:\d
{2} \#} $line]} {
45 # Return value for INFO property
46 proc status
{r property
} {
47 if {[regexp "\r\n$property:(.*?)\r\n" [$r info] _ value
]} {
52 proc waitForBgsave r
{
54 if {[status r bgsave_in_progress
] eq
1} {
55 puts -nonewline "\nWaiting for background save to finish... "
64 proc waitForBgrewriteaof r
{
66 if {[status r bgrewriteaof_in_progress
] eq
1} {
67 puts -nonewline "\nWaiting for background AOF rewrite to finish... "
76 proc wait_for_sync r
{
78 if {[status r master_link_status
] eq
"down"} {
86 proc randomInt
{max
} {
87 expr {int
(rand
()*$max)}
91 set path
[expr {int
(rand
()*[llength $args])}]
92 uplevel 1 [lindex $args $path]
97 # Small enough to likely collide
100 # 32 bit compressible signed/unsigned
101 randpath
{randomInt
2000000000} {randomInt
4000000000}
104 randpath
{randomInt
1000000000000}
107 randpath
{randstring
0 256 alpha
} \
108 {randstring
0 256 compr
} \
109 {randstring
0 256 binary}
115 # Small enough to likely collide
118 # 32 bit compressible signed/unsigned
119 randpath
{randomInt
2000000000} {randomInt
4000000000}
122 randpath
{randomInt
1000000000000}
125 randpath
{randstring
1 256 alpha
} \
126 {randstring
1 256 compr
}
130 proc createComplexDataset
{r ops
} {
131 for {set j
0} {$j < $ops} {incr j
} {
136 set d
[expr {rand
()}]
138 set d
[expr {rand
()}]
140 set d
[expr {rand
()}]
142 set d
[expr {rand
()}]
144 set d
[expr {rand
()}]
146 randpath
{set d
+inf
} {set d
-inf}
170 randpath
{$r lpush
$k $v} \
177 randpath
{$r sadd
$k $v} \
181 randpath
{$r zadd
$k $d $v} \
185 randpath
{$r hset
$k $f $v} \
192 proc formatCommand
{args
} {
193 set cmd
"*[llength $args]\r\n"
195 append cmd
"$[string length $a]\r\n$a\r\n"