Skip to content

Commit

Permalink
Modify the redis test script to titan
Browse files Browse the repository at this point in the history
  • Loading branch information
lugang committed Jul 4, 2019
1 parent 8aa1c9d commit 7113333
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 51 deletions.
14 changes: 14 additions & 0 deletions tests/redis/README.md
@@ -0,0 +1,14 @@
Description:
* You need to install tcl 8.5 or higher(same as redis 5.0.5)
* After testing, you need to cleanup the test data by sending flushdb commands or manually deleting it before you can test other types.

command:
```
tclsh test_helper.tcl --single <test file path> --host <ip> --port <port> --auth <token>
```
* single # Specify a test file in ./unit or ./unit/type directory, eg : --single unit/type/string
* host # the server's ip which we need to test
* port # the server's port which we need to test
* auth # the token


8 changes: 4 additions & 4 deletions tests/redis/instances.tcl
Expand Up @@ -10,10 +10,10 @@
package require Tcl 8.5

set tcl_precision 17
source ../support/redis.tcl
source ../support/util.tcl
source ../support/server.tcl
source ../support/test.tcl
source support/redis.tcl
source support/util.tcl
source support/server.tcl
source support/test.tcl

set ::verbose 0
set ::valgrind 0
Expand Down
1 change: 1 addition & 0 deletions tests/redis/support/server.tcl
Expand Up @@ -147,6 +147,7 @@ proc start_server {options {code undefined}} {
dict set srv "port" $::port
set client [redis $::host $::port]
dict set srv "client" $client
$client auth $::auth
$client select 9

# append the server to the stack
Expand Down
5 changes: 5 additions & 0 deletions tests/redis/support/test.tcl
Expand Up @@ -5,6 +5,8 @@ set ::num_skipped 0
set ::num_aborted 0
set ::tests_failed {}

source support/test_common.tcl

proc fail {msg} {
error "assertion:$msg"
}
Expand Down Expand Up @@ -67,6 +69,9 @@ proc wait_for_condition {maxtries delay e _else_ elsescript} {
}

proc test {name code {okpattern undefined}} {
if { ![info exists ::toTestCase($name)] } {
return
}
# abort if tagged with a tag to deny
foreach tag $::denytags {
if {[lsearch $::tags $tag] >= 0} {
Expand Down
190 changes: 190 additions & 0 deletions tests/redis/support/test_common.tcl
@@ -0,0 +1,190 @@
array set ::toTestCase {
#string test
"SET and GET an item" 1
"SET and GET an empty item" 1
"Very big payload in GET/SET" 1
"Very big payload random access" 1
"SET 10000 numeric keys and access all them in reverse order" 1
"SETNX target key missing" 1
"SETNX target key exists" 1
"SETNX against not-expired volatile key" 1
"SETNX against expired volatile key" 1
"MGET" 1
"MGET against non existing key" 1
"MGET against non-string key" 1
"MSET base case" 1
"MSET wrong number of args" 1
"MSETNX with already existent key" 1
"MSETNX with not existing keys" 1
"STRLEN against non-existing key" 1
"STRLEN against integer-encoded value" 1
"STRLEN against plain string" 1
"SETRANGE against non-existing key" 1
"SETRANGE against string-encoded key" 1
"SETRANGE against key with wrong type" 1
"SETRANGE with out of range offset" 1
"GETRANGE against non-existing key" 1
"GETRANGE against string value" 1
"GETRANGE fuzzing" 1
"Extended SET can detect syntax errors" 1
"Extended SET NX option" 1
"Extended SET XX option" 1
"Extended SET EX option" 1
"Extended SET PX option" 1
"Extended SET using multiple options at once" 1
"GETRANGE with huge ranges, Github issue #1844" 1

#set test
"SADD, SCARD, SISMEMBER, SMEMBERS basics - regular set" 1
"SADD against non set" 1
"SADD an integer larger than 64 bits" 1
"Variadic SADD" 1
"SREM basics - regular set" 1
"SREM with multiple arguments" 1
"SREM variadic version with more args needed to destroy the key" 1
"Generated sets must be encoded as hashtable" 1
"SINTER with two sets - hashtable" 1
"SINTER against three sets - hashtable" 1
"SUNION with non existing keys - hashtable" 1
"SDIFF with two sets - hashtable" 1
"SDIFF with three sets - hashtable" 1
"SDIFF with first set empty" 1
"SDIFF with same set two times" 1
"SDIFF fuzzing" 1
"SINTER against non-set should throw error" 1
"SUNION against non-set should throw error" 1
"SINTER should handle non existing key as empty" 1
"SPOP basics - hashtable" 1
"SPOP with <count>=1 - hashtable" 1
"SPOP with <count>" 1
"SPOP new implementation: code path #1" 1
"SPOP new implementation: code path #2" 1
"SPOP new implementation: code path #3" 1
#list test
"LPUSH, RPUSH, LLENGTH, LINDEX, LPOP - regular list" 1
"R/LPOP against empty list" 1
"Variadic RPUSH/LPUSH" 1
"DEL a list" 1
"LPUSHX, RPUSHX - generic" 1
"LINSERT raise error on bad syntax" 1
"LLEN against non-list value error" 1
"LLEN against non existing key" 1
"LINDEX against non-list value error" 1
"LINDEX against non existing key" 1
"LPUSH against non-list value error" 1
"RPUSH against non-list value error" 1
"LRANGE basics - linkedlist" 1
"LRANGE inverted indexes - linkedlist" 1
"LRANGE out of range indexes including the full list - linkedlist" 1
"LRANGE out of range negative end index - linkedlist" 1
"LRANGE against non existing key" 1
"LSET - linkedlist" 1
"LSET out of range index - linkedlist" 1
"LSET against non existing key" 1
"LSET against non list value" 1


#list3 test
"Explicit regression for a list bug" 1
"Regression for quicklist #3343 bug" 1

#zset test
"Check encoding - hashtable" 1
"ZSET basic ZADD and score update - hashtable" 1
"ZSET element can't be set to NaN with ZADD - hashtable" 1
"ZSET element can't be set to NaN with ZINCRBY" 1
"ZADD with options syntax error with incomplete pair" 1
"ZADD XX returns the number of elements actually added" 1
"ZADD - Variadic version base case" 1
"ZADD - Return value is the number of actually added items" 1
"ZADD - Variadic version does not add nothing on single parsing err" 1
"ZADD - Variadic version will raise error on missing arg" 1
"ZCARD basics - hashtable" 1
"ZREM removes key after last element is removed" 1
"ZREM variadic version" 1
"ZREM variadic version -- remove elements after key deletion" 1
"ZRANGE basics - hashtable" 1
"ZREVRANGE basics - hashtable" 1
"ZSET commands don't accept the empty strings as valid score" 1
"ZSCORE - hashtable" 1
"ZSET sorting stresser - hashtable" 1
"ZSETs skiplist implementation backlink consistency test - hashtable" 1

#hash test
"HSET/HLEN - Small hash creation" 1
"HSET/HLEN - Big hash creation" 1
"Is the big hash encoded with an hash table?" 1
"HGET against the small hash" 1
"HGET against the big hash" 1
"HGET against non existing key" 1
"HSET in update and insert mode" 1
"HSETNX target key missing - small hash" 1
"HSETNX target key exists - small hash" 1
"HSETNX target key missing - big hash" 1
"HSETNX target key exists - big hash" 1
"HMSET wrong number of args" 1


"HMGET against non existing key and fields" 1
"HMGET against wrong type" 1
"HMGET - small hash" 1
"HMGET - big hash" 1
"HKEYS - small hash" 1
"HKEYS - big hash" 1
"HVALS - small hash" 1
"HVALS - big hash" 1
"HGETALL - small hash" 1
"HGETALL - big hash" 1
"HDEL and return value" 1
"HDEL - more than a single value" 1
"HDEL - hash becomes empty before deleting all specified fields" 1
"HEXISTS" 1
"Is a ziplist encoded Hash promoted on big payload?" 1
"HINCRBY against non existing database key" 1
"HINCRBY against non existing hash key" 1
"HINCRBY against hash key created by hincrby itself" 1
"HINCRBY against hash key originally set with HSET" 1
"HINCRBY over 32bit value" 1
"HINCRBY over 32bit value with over 32bit increment" 1
"HINCRBY fails against hash value with spaces (left)" 1
"HINCRBY fails against hash value with spaces (right)" 1
"HINCRBY can detect overflows" 1
"HINCRBYFLOAT against non existing database key" 1
"HINCRBYFLOAT against non existing hash key" 1
"HINCRBYFLOAT against hash key created by hincrby itself" 1
"HINCRBYFLOAT against hash key originally set with HSET" 1
"HINCRBYFLOAT over 32bit value" 1
"HINCRBYFLOAT over 32bit value with over 32bit increment" 1
"HINCRBYFLOAT fails against hash value with spaces (left)" 1
"HINCRBYFLOAT fails against hash value with spaces (right)" 1
"HSTRLEN against the small hash" 1
"HSTRLEN against the big hash" 1
"HSTRLEN against non existing field" 1






"Test HINCRBYFLOAT for correct float representation (issue #2846)" 1

#expire test
"EXPIRE - set timeouts multiple times" 1
"EXPIRE - It should be still possible to read 'x'" 1
"EXPIRE - After 2.1 seconds the key should no longer be here" 1
"EXPIRE - write on expire should work" 1
"EXPIREAT - Check for EXPIRE alike behavior" 1
"SETEX - Set + Expire combo operation. Check for TTL" 1
"SETEX - Check value" 1
"SETEX - Overwrite old key" 1
"SETEX - Wait for the key to expire" 1
"SETEX - Wrong time parameter" 1
"EXPIRE pricision is now the millisecond" 1
"PEXPIRE/PSETEX/PEXPIREAT can set sub-second expires" 1
"TTL returns time to live in seconds" 1
"PTTL returns time to live in milliseconds" 1
"TTL / PTTL return -1 if key has no expire" 1
"TTL / PTTL return -2 if key does not exit" 1
"5 keys in, 5 keys out" 1
"EXPIRE with empty string as TTL should report an error" 1
}
23 changes: 14 additions & 9 deletions tests/redis/test_helper.tcl
Expand Up @@ -5,11 +5,11 @@
package require Tcl 8.5

set tcl_precision 17
source tests/support/redis.tcl
source tests/support/server.tcl
source tests/support/tmpfile.tcl
source tests/support/test.tcl
source tests/support/util.tcl
source support/redis.tcl
source support/server.tcl
source support/tmpfile.tcl
source support/test.tcl
source support/util.tcl

set ::all_tests {
unit/printver
Expand Down Expand Up @@ -68,6 +68,7 @@ set ::next_test 0

set ::host 127.0.0.1
set ::port 21111
set ::auth ""
set ::traceleaks 0
set ::valgrind 0
set ::stack_logging 0
Expand Down Expand Up @@ -101,7 +102,7 @@ set ::client 0
set ::numclients 16

proc execute_tests name {
set path "tests/$name.tcl"
set path "$name.tcl"
set ::curfile $path
source $path
send_data_packet $::test_server_fd done "$name"
Expand Down Expand Up @@ -207,13 +208,12 @@ proc test_server_main {} {

# Start the client instances
set ::clients_pids {}
set start_port [expr {$::port+100}]
set start_port $::port

for {set j 0} {$j < $::numclients} {incr j} {
set start_port [find_available_port $start_port]
set p [exec $tclsh [info script] {*}$::argv \
--client $port --port $start_port &]
lappend ::clients_pids $p
incr start_port 10
}

# Setup global state for the test server
Expand Down Expand Up @@ -432,6 +432,7 @@ proc send_data_packet {fd status data} {

proc print_help_screen {} {
puts [join {
"--auth Specify the AUTH."
"--valgrind Run the test over valgrind."
"--stack-logging Enable OSX leaks/malloc stack logging."
"--accurate Run slow randomized tests for more iterations."
Expand Down Expand Up @@ -466,6 +467,9 @@ for {set j 0} {$j < [llength $argv]} {incr j} {
}
}
incr j
} elseif {$opt eq {--auth}} {
set ::auth $arg
incr j
} elseif {$opt eq {--config}} {
set arg2 [lindex $argv [expr $j+2]]
lappend ::global_overrides $arg
Expand Down Expand Up @@ -561,6 +565,7 @@ if {$::skip_till != ""} {
# in case there was some filter, that is --single or --skip-till options.
if {[llength $::single_tests] > 0} {
set ::all_tests $::single_tests
set ::numclients 1
}

proc attach_to_replication_stream {} {
Expand Down
2 changes: 1 addition & 1 deletion tests/redis/unit/type/list-2.tcl
Expand Up @@ -4,7 +4,7 @@ start_server {
"list-max-ziplist-size" 4
}
} {
source "tests/unit/type/list-common.tcl"
source "unit/type/list-common.tcl"

foreach {type large} [array get largevalue] {
tags {"slow"} {
Expand Down
2 changes: 0 additions & 2 deletions tests/redis/unit/type/list-3.tcl
Expand Up @@ -39,8 +39,6 @@ start_server {
switch $op {
0 {r lpush key $ele}
1 {r rpush key $ele}
2 {r lpop key}
3 {r rpop key}
4 {
catch {r lset key $small_signed_count $ele}
}
Expand Down
10 changes: 4 additions & 6 deletions tests/redis/unit/type/list.tcl
Expand Up @@ -4,7 +4,7 @@ start_server {
"list-max-ziplist-size" 5
}
} {
source "tests/unit/type/list-common.tcl"
source "unit/type/list-common.tcl"

test {LPUSH, RPUSH, LLENGTH, LINDEX, LPOP - ziplist} {
# first lpush then rpush
Expand Down Expand Up @@ -37,28 +37,26 @@ start_server {
test {LPUSH, RPUSH, LLENGTH, LINDEX, LPOP - regular list} {
# first lpush then rpush
assert_equal 1 [r lpush mylist1 $largevalue(linkedlist)]
assert_encoding quicklist mylist1
assert_encoding linkedlist mylist1
assert_equal 2 [r rpush mylist1 b]
assert_equal 3 [r rpush mylist1 c]
assert_equal 3 [r llen mylist1]
assert_equal $largevalue(linkedlist) [r lindex mylist1 0]
assert_equal b [r lindex mylist1 1]
assert_equal c [r lindex mylist1 2]
assert_equal {} [r lindex mylist1 3]
assert_equal c [r rpop mylist1]
assert_equal $largevalue(linkedlist) [r lpop mylist1]

# first rpush then lpush
assert_equal 1 [r rpush mylist2 $largevalue(linkedlist)]
assert_encoding quicklist mylist2
assert_encoding linkedlist mylist2
assert_equal 2 [r lpush mylist2 b]
assert_equal 3 [r lpush mylist2 c]
assert_equal 3 [r llen mylist2]
assert_equal c [r lindex mylist2 0]
assert_equal b [r lindex mylist2 1]
assert_equal $largevalue(linkedlist) [r lindex mylist2 2]
assert_equal {} [r lindex mylist2 3]
assert_equal $largevalue(linkedlist) [r rpop mylist2]
assert_equal c [r lpop mylist2]
}

Expand All @@ -82,7 +80,7 @@ start_server {
proc create_list {key entries} {
r del $key
foreach entry $entries { r rpush $key $entry }
assert_encoding quicklist $key
assert_encoding linkedlist $key
}

foreach {type large} [array get largevalue] {
Expand Down

0 comments on commit 7113333

Please sign in to comment.