Commit 819d291b authored by Oran Agra's avatar Oran Agra
Browse files

Merge remote-tracking branch 'origin/unstable' into 7.2

parents a51eb05b 936cfa46
source tests/support/cluster.tcl
proc get_port_from_moved_error {e} {
set ip_port [lindex [split $e " "] 2]
return [lindex [split $ip_port ":"] 1]
}
proc get_pport_by_port {port} {
foreach srv $::servers {
set srv_port [dict get $srv port]
if {$port == $srv_port} {
return [dict get $srv pport]
}
}
return 0
}
proc get_port_from_node_info {line} {
set fields [split $line " "]
set addr [lindex $fields 1]
set ip_port [lindex [split $addr "@"] 0]
return [lindex [split $ip_port ":"] 1]
}
proc cluster_response_tls {tls_cluster} {
test "CLUSTER SLOTS with different connection type -- tls-cluster $tls_cluster" {
set slots1 [R 0 cluster slots]
set pport [srv 0 pport]
set cluster_client [redis_cluster 127.0.0.1:$pport 0]
set slots2 [$cluster_client cluster slots]
$cluster_client close
# Compare the ports in the first row
assert_no_match [lindex $slots1 0 2 1] [lindex $slots2 0 2 1]
}
test "CLUSTER NODES return port according to connection type -- tls-cluster $tls_cluster" {
set nodes [R 0 cluster nodes]
set port1 [get_port_from_node_info [lindex [split $nodes "\r\n"] 0]]
set pport [srv 0 pport]
set cluster_client [redis_cluster 127.0.0.1:$pport 0]
set nodes [$cluster_client cluster nodes]
set port2 [get_port_from_node_info [lindex [split $nodes "\r\n"] 0]]
$cluster_client close
assert_not_equal $port1 $port2
}
set cluster [redis_cluster 127.0.0.1:[srv 0 port]]
set cluster_pport [redis_cluster 127.0.0.1:[srv 0 pport] 0]
$cluster refresh_nodes_map
test "Set many keys in the cluster -- tls-cluster $tls_cluster" {
for {set i 0} {$i < 5000} {incr i} {
$cluster set $i $i
assert { [$cluster get $i] eq $i }
}
}
test "Test cluster responses during migration of slot x -- tls-cluster $tls_cluster" {
set slot 10
array set nodefrom [$cluster masternode_for_slot $slot]
array set nodeto [$cluster masternode_notfor_slot $slot]
$nodeto(link) cluster setslot $slot importing $nodefrom(id)
$nodefrom(link) cluster setslot $slot migrating $nodeto(id)
# Get a key from that slot
set key [$nodefrom(link) cluster GETKEYSINSLOT $slot "1"]
# MOVED REPLY
catch {$nodeto(link) set $key "newVal"} e_moved1
assert_match "*MOVED*" $e_moved1
# ASK REPLY
catch {$nodefrom(link) set "abc{$key}" "newVal"} e_ask1
assert_match "*ASK*" $e_ask1
# UNSTABLE REPLY
assert_error "*TRYAGAIN*" {$nodefrom(link) mset "a{$key}" "newVal" $key "newVal2"}
# Connecting using another protocol
array set nodefrom_pport [$cluster_pport masternode_for_slot $slot]
array set nodeto_pport [$cluster_pport masternode_notfor_slot $slot]
# MOVED REPLY
catch {$nodeto_pport(link) set $key "newVal"} e_moved2
assert_match "*MOVED*" $e_moved2
# ASK REPLY
catch {$nodefrom_pport(link) set "abc{$key}" "newVal"} e_ask2
assert_match "*ASK*" $e_ask2
# Compare MOVED error's port
set port1 [get_port_from_moved_error $e_moved1]
set port2 [get_port_from_moved_error $e_moved2]
assert_not_equal $port1 $port2
assert_equal $port1 $nodefrom(port)
assert_equal $port2 [get_pport_by_port $nodefrom(port)]
# Compare ASK error's port
set port1 [get_port_from_moved_error $e_ask1]
set port2 [get_port_from_moved_error $e_ask2]
assert_not_equal $port1 $port2
assert_equal $port1 $nodeto(port)
assert_equal $port2 [get_pport_by_port $nodeto(port)]
}
}
if {$::tls} {
start_cluster 3 3 {tags {external:skip cluster tls} overrides {tls-cluster yes tls-replication yes}} {
cluster_response_tls yes
}
start_cluster 3 3 {tags {external:skip cluster tls} overrides {tls-cluster no tls-replication no}} {
cluster_response_tls no
}
}
# Returns 1 if no node knows node_id, 0 if any node knows it.
proc node_is_forgotten {node_id} {
for {set j 0} {$j < [llength $::servers]} {incr j} {
set cluster_nodes [R $j CLUSTER NODES]
if { [string match "*$node_id*" $cluster_nodes] } {
return 0
}
}
return 1
}
# Isolate a node from the cluster and give it a new nodeid
proc isolate_node {id} {
set node_id [R $id CLUSTER MYID]
R $id CLUSTER RESET HARD
# Here we additionally test that CLUSTER FORGET propagates to all nodes.
set other_id [expr $id == 0 ? 1 : 0]
R $other_id CLUSTER FORGET $node_id
wait_for_condition 50 100 {
[node_is_forgotten $node_id]
} else {
fail "CLUSTER FORGET was not propagated to all nodes"
}
}
# Check if cluster's view of hostnames is consistent
proc are_hostnames_propagated {match_string} {
for {set j 0} {$j < [llength $::servers]} {incr j} {
set cfg [R $j cluster slots]
foreach node $cfg {
for {set i 2} {$i < [llength $node]} {incr i} {
if {! [string match $match_string [lindex [lindex [lindex $node $i] 3] 1]] } {
return 0
}
}
}
}
return 1
}
proc get_slot_field {slot_output shard_id node_id attrib_id} {
return [lindex [lindex [lindex $slot_output $shard_id] $node_id] $attrib_id]
}
......
# Check if cluster's view of human announced nodename is reported in logs
start_cluster 3 0 {tags {external:skip cluster}} {
test "Set cluster human announced nodename and let it propagate" {
for {set j 0} {$j < [llength $::servers]} {incr j} {
R $j config set cluster-announce-hostname "host-$j.com"
R $j config set cluster-announce-human-nodename "nodename-$j"
}
# We wait for everyone to agree on the hostnames. Since they are gossiped
# the same way as nodenames, it implies everyone knows the nodenames too.
wait_for_condition 50 100 {
[are_hostnames_propagated "host-*.com"] eq 1
} else {
fail "cluster hostnames were not propagated"
}
}
test "Human nodenames are visible in log messages" {
# Pause instance 0, so everyone thinks it is dead
pause_process [srv 0 pid]
# We're going to use a message we will know will be sent, node unreachable,
# since it includes the other node gossiping.
wait_for_log_messages -1 {"*Node * (nodename-2) reported node * (nodename-0) as not reachable*"} 0 20 500
wait_for_log_messages -2 {"*Node * (nodename-1) reported node * (nodename-0) as not reachable*"} 0 20 500
resume_process [srv 0 pid]
}
}
......@@ -18,7 +18,6 @@ start_cluster 2 2 {tags {external:skip cluster}} {
set id [R 0 CLUSTER MYID]
assert_equal {0} [R 0 CLUSTER count-failure-reports $id]
assert_match "*shard-id*" [R 0 CLUSTER slaves $id]
R 0 flushall
assert_equal {OK} [R 0 CLUSTER flushslots]
......
......@@ -48,6 +48,17 @@ test "Continuous slots distribution" {
assert_match "*13105 13500*14001 15000*16001 16383*" [$master5 CLUSTER SLOTS]
}
test "ADDSLOTS command with several boundary conditions test suite" {
assert_error "ERR Invalid or out of range slot" {R 0 cluster ADDSLOTS 3001 aaa}
assert_error "ERR Invalid or out of range slot" {R 0 cluster ADDSLOTS 3001 -1000}
assert_error "ERR Invalid or out of range slot" {R 0 cluster ADDSLOTS 3001 30003}
assert_error "ERR Slot 3200 is already busy" {R 0 cluster ADDSLOTS 3200}
assert_error "ERR Slot 8501 is already busy" {R 0 cluster ADDSLOTS 8501}
assert_error "ERR Slot 3001 specified multiple times" {R 0 cluster ADDSLOTS 3001 3002 3001}
}
test "ADDSLOTSRANGE command with several boundary conditions test suite" {
# Add multiple slots with incorrect argument number
assert_error "ERR wrong number of arguments for 'cluster|addslotsrange' command" {R 0 cluster ADDSLOTSRANGE 3001 3020 3030}
......
......@@ -96,6 +96,34 @@ start_server {tags {"dump"}} {
set e
} {*syntax*}
test {RESTORE should not store key that are already expired, with REPLACE will propagate it as DEL or UNLINK} {
r del key1{t} key2{t}
r set key1{t} value2
r lpush key2{t} 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
r set key{t} value
set encoded [r dump key{t}]
set now [clock milliseconds]
set repl [attach_to_replication_stream]
# Keys that have expired will not be stored.
r config set lazyfree-lazy-server-del no
assert_equal {OK} [r restore key1{t} [expr $now-5000] $encoded replace absttl]
r config set lazyfree-lazy-server-del yes
assert_equal {OK} [r restore key2{t} [expr $now-5000] $encoded replace absttl]
assert_equal {0} [r exists key1{t} key2{t}]
# Verify the propagate of DEL and UNLINK.
assert_replication_stream $repl {
{select *}
{del key1{t}}
{unlink key2{t}}
}
close_replication_stream $repl
} {} {needs:repl}
test {DUMP of non existing key returns nil} {
r dump nonexisting_key
} {}
......
......@@ -321,7 +321,7 @@ start_server {tags {"expire"}} {
r set foo1 bar ex 100
r set foo2 bar px 100000
r set foo3 bar exat [expr [clock seconds]+100]
r set foo4 bar pxat [expr [clock milliseconds]+100000]
r set foo4 bar PXAT [expr [clock milliseconds]+100000]
r setex foo5 100 bar
r psetex foo6 100000 bar
# EXPIRE-family commands
......@@ -491,7 +491,7 @@ start_server {tags {"expire"}} {
{set foo1 bar PXAT *}
{set foo1 bar PXAT *}
{set foo1 bar PXAT *}
{set foo1 bar PXAT *}
{set foo1 bar pxat *}
{set foo1 bar PXAT *}
{set foo1 bar PXAT *}
{set foo2 bar}
......
......@@ -99,6 +99,18 @@ proc verify_geo_edge_response_bymember {expected_response expected_store_respons
assert_match $expected_store_response $response
}
proc verify_geo_edge_response_generic {expected_response} {
catch {r geodist src{t} member 1 km} response
assert_match $expected_response $response
catch {r geohash src{t} member} response
assert_match $expected_response $response
catch {r geopos src{t} member} response
assert_match $expected_response $response
}
# The following list represents sets of random seed, search position
# and radius that caused bugs in the past. It is used by the randomized
# test later as a starting point. When the regression vectors are scanned
......@@ -128,6 +140,7 @@ start_server {tags {"geo"}} {
verify_geo_edge_response_bylonlat "WRONGTYPE*" "WRONGTYPE*"
verify_geo_edge_response_bymember "WRONGTYPE*" "WRONGTYPE*"
verify_geo_edge_response_generic "WRONGTYPE*"
}
test {GEO with non existing src key} {
......
......@@ -287,21 +287,26 @@ start_server {tags {"info" "external:skip"}} {
set cycle2 [getInfoProperty $info2 eventloop_cycles]
set el_sum2 [getInfoProperty $info2 eventloop_duration_sum]
set cmd_sum2 [getInfoProperty $info2 eventloop_duration_cmd_sum]
if {$::verbose} { puts "eventloop metrics cycle1: $cycle1, cycle2: $cycle2" }
assert_morethan $cycle2 $cycle1
assert_lessthan $cycle2 [expr $cycle1+10] ;# we expect 2 or 3 cycles here, but allow some tolerance
if {$::verbose} { puts "eventloop metrics el_sum1: $el_sum1, el_sum2: $el_sum2" }
assert_morethan $el_sum2 $el_sum1
assert_lessthan $el_sum2 [expr $el_sum1+5000] ;# we expect roughly 100ms here, but allow some tolerance
assert_lessthan $el_sum2 [expr $el_sum1+30000] ;# we expect roughly 100ms here, but allow some tolerance
if {$::verbose} { puts "eventloop metrics cmd_sum1: $cmd_sum1, cmd_sum2: $cmd_sum2" }
assert_morethan $cmd_sum2 $cmd_sum1
assert_lessthan $cmd_sum2 [expr $cmd_sum1+3000] ;# we expect about tens of ms here, but allow some tolerance
assert_lessthan $cmd_sum2 [expr $cmd_sum1+15000] ;# we expect about tens of ms here, but allow some tolerance
}
test {stats: instantaneous metrics} {
r config resetstat
after 1600 ;# hz is 10, wait for 16 cron tick so that sample array is fulfilled
set value [s instantaneous_eventloop_cycles_per_sec]
if {$::verbose} { puts "instantaneous metrics instantaneous_eventloop_cycles_per_sec: $value" }
assert_morethan $value 0
assert_lessthan $value 15 ;# default hz is 10
set value [s instantaneous_eventloop_duration_usec]
if {$::verbose} { puts "instantaneous metrics instantaneous_eventloop_duration_usec: $value" }
assert_morethan $value 0
assert_lessthan $value 22000 ;# default hz is 10, so duration < 1000 / 10, allow some tolerance
}
......
......@@ -153,6 +153,21 @@ start_server {tags {"introspection"}} {
assert_equal {key1 key2} [r command getkeys lcs key1 key2]
}
test {COMMAND GETKEYS MORE THAN 256 KEYS} {
set all_keys [list]
set numkeys 260
for {set i 1} {$i <= $numkeys} {incr i} {
lappend all_keys "key$i"
}
set all_keys_with_target [linsert $all_keys 0 target]
# we are using ZUNIONSTORE command since in order to reproduce allocation of a new buffer in getKeysPrepareResult
# when numkeys in result > 0
# we need a command that the final number of keys is not known in the first call to getKeysPrepareResult
# before the fix in that case data of old buffer was not copied to the new result buffer
# causing all previous keys (numkeys) data to be uninitialize
assert_equal $all_keys_with_target [r command getkeys ZUNIONSTORE target $numkeys {*}$all_keys]
}
test "COMMAND LIST syntax error" {
assert_error "ERR syntax error*" {r command list bad_arg}
assert_error "ERR syntax error*" {r command list filterby bad_arg}
......
......@@ -275,27 +275,6 @@ start_server {tags {"introspection"}} {
r client list
} {*name= *}
test {Coverage: Basic CLIENT CACHING} {
set rd_redirection [redis_deferring_client]
$rd_redirection client id
set redir_id [$rd_redirection read]
r CLIENT TRACKING on OPTIN REDIRECT $redir_id
r CLIENT CACHING yes
r CLIENT TRACKING off
} {OK}
test {Coverage: Basic CLIENT REPLY} {
r CLIENT REPLY on
} {OK}
test {Coverage: Basic CLIENT TRACKINGINFO} {
r CLIENT TRACKINGINFO
} {flags off redirect -1 prefixes {}}
test {Coverage: Basic CLIENT GETREDIR} {
r CLIENT GETREDIR
} {-1}
test {CLIENT SETNAME does not accept spaces} {
catch {r client setname "foo bar"} e
set e
......@@ -652,6 +631,10 @@ start_server {tags {"introspection"}} {
}
test {redis-server command line arguments - error cases} {
# Take '--invalid' as the option.
catch {exec src/redis-server --invalid} err
assert_match {*Bad directive or wrong number of arguments*} $err
catch {exec src/redis-server --port} err
assert_match {*'port'*wrong number of arguments*} $err
......
......@@ -571,3 +571,20 @@ start_server {tags {"maxmemory" "external:skip"}} {
r config set maxmemory-policy noeviction
}
}
start_server {tags {"maxmemory" "external:skip"}} {
test {lru/lfu value of the key just added} {
r config set maxmemory-policy allkeys-lru
r set foo a
assert {[r object idletime foo] <= 2}
r del foo
r set foo 1
r get foo
assert {[r object idletime foo] <= 2}
r config set maxmemory-policy allkeys-lfu
r del foo
r set foo a
assert {[r object freq foo] == 5}
}
}
......@@ -15,7 +15,18 @@ start_server {tags {"modules"}} {
assert_equal {0} [r llen l]
}
foreach cmd {do_rm_call_async do_rm_call_async_script_mode} {
test "Blpop on threaded async RM_Call" {
set rd [redis_deferring_client]
$rd do_rm_call_async_on_thread blpop l 0
wait_for_blocked_clients_count 1
r lpush l a
assert_equal [$rd read] {l a}
wait_for_blocked_clients_count 0
$rd close
}
foreach cmd {do_rm_call_async do_rm_call_async_script_mode } {
test "Blpop on async RM_Call using $cmd" {
set rd [redis_deferring_client]
......@@ -25,6 +36,7 @@ start_server {tags {"modules"}} {
r lpush l a
assert_equal [$rd read] {l a}
wait_for_blocked_clients_count 0
$rd close
}
test "Brpop on async RM_Call using $cmd" {
......@@ -35,6 +47,7 @@ start_server {tags {"modules"}} {
r lpush l a
assert_equal [$rd read] {l a}
wait_for_blocked_clients_count 0
$rd close
}
test "Brpoplpush on async RM_Call using $cmd" {
......@@ -45,6 +58,7 @@ start_server {tags {"modules"}} {
r lpush l1 a
assert_equal [$rd read] {a}
wait_for_blocked_clients_count 0
$rd close
r lpop l2
} {a}
......@@ -56,6 +70,7 @@ start_server {tags {"modules"}} {
r lpush l1 a
assert_equal [$rd read] {a}
wait_for_blocked_clients_count 0
$rd close
r lpop l2
} {a}
......@@ -67,6 +82,7 @@ start_server {tags {"modules"}} {
r zadd s 10 foo
assert_equal [$rd read] {s foo 10}
wait_for_blocked_clients_count 0
$rd close
}
test "Bzpopmax on async RM_Call using $cmd" {
......@@ -77,6 +93,7 @@ start_server {tags {"modules"}} {
r zadd s 10 foo
assert_equal [$rd read] {s foo 10}
wait_for_blocked_clients_count 0
$rd close
}
}
......@@ -88,6 +105,7 @@ start_server {tags {"modules"}} {
r lpush l a
assert_equal [$rd read] {l a}
wait_for_blocked_clients_count 0
$rd close
}
test {Test multiple async RM_Call waiting on the same event} {
......@@ -101,6 +119,8 @@ start_server {tags {"modules"}} {
assert_equal [$rd1 read] {l element}
assert_equal [$rd2 read] {l element}
wait_for_blocked_clients_count 0
$rd1 close
$rd2 close
}
test {async RM_Call calls RM_Call} {
......@@ -136,6 +156,7 @@ start_server {tags {"modules"}} {
}
wait_for_blocked_clients_count 0
$rd close
}
test {Become replica while having async RM_Call running} {
......@@ -156,6 +177,7 @@ start_server {tags {"modules"}} {
r lpush l 1
# make sure the async rm_call was aborted
assert_equal [r llen l] {1}
$rd close
}
test {Pipeline with blocking RM_Call} {
......@@ -175,6 +197,7 @@ start_server {tags {"modules"}} {
assert_equal [$rd read] {PONG}
wait_for_blocked_clients_count 0
$rd close
}
test {blocking RM_Call abort} {
......@@ -195,6 +218,7 @@ start_server {tags {"modules"}} {
r lpush l 1
# make sure the async rm_call was aborted
assert_equal [r llen l] {1}
$rd close
}
}
......@@ -220,6 +244,7 @@ start_server {tags {"modules"}} {
close_replication_stream $repl
wait_for_blocked_clients_count 0
$rd close
}
test {Test unblock handler are executed as a unit} {
......@@ -245,6 +270,7 @@ start_server {tags {"modules"}} {
close_replication_stream $repl
wait_for_blocked_clients_count 0
$rd close
}
test {Test no propagation of blocking command} {
......@@ -269,6 +295,7 @@ start_server {tags {"modules"}} {
close_replication_stream $repl
wait_for_blocked_clients_count 0
$rd close
}
}
......@@ -303,6 +330,7 @@ start_server {tags {"modules"}} {
close_replication_stream $repl
wait_for_blocked_clients_count 0
$rd close
}
test {Test unblock handler are executed as a unit with lazy expire} {
......@@ -355,9 +383,10 @@ start_server {tags {"modules"}} {
}
close_replication_stream $repl
r DEBUG SET-ACTIVE-EXPIRE 1
}
wait_for_blocked_clients_count 0
$rd close
}
}
start_server {tags {"modules"}} {
......@@ -376,5 +405,6 @@ start_server {tags {"modules"}} {
assert_equal [$rd read] {4}
wait_for_blocked_clients_count 0
$rd close
}
}
......@@ -253,6 +253,34 @@ foreach call_type {nested normal} {
assert_match {*calls=2,*,rejected_calls=0,failed_calls=2} [cmdrstat do_bg_rm_call r]
}
set master [srv 0 client]
set master_host [srv 0 host]
set master_port [srv 0 port]
start_server [list overrides [list loadmodule "$testmodule"]] {
set replica [srv 0 client]
set replica_host [srv 0 host]
set replica_port [srv 0 port]
# Start the replication process...
$replica replicaof $master_host $master_port
wait_for_sync $replica
test {WAIT command on module blocked client} {
pause_process [srv 0 pid]
$master do_bg_rm_call_format ! hset bk1 foo bar
assert_equal [$master wait 1 1000] 0
resume_process [srv 0 pid]
assert_equal [$master wait 1 1000] 1
assert_equal [$replica hget bk1 foo] bar
}
}
test {Unblock by timer} {
assert_match "OK" [r unblock_by_timer 100]
}
test "Unload the module - blockedclient" {
assert_equal {OK} [r module unload blockedclient]
}
......
......@@ -34,6 +34,31 @@ start_server {tags {"modules"}} {
assert_equal {42} [r fsl.getall src]
}
test "Module client blocked on keys: BPOPPUSH unblocked by timer" {
set rd1 [redis_deferring_client]
r del src dst
set repl [attach_to_replication_stream]
$rd1 fsl.bpoppush src dst 0
wait_for_blocked_clients_count 1
r fsl.pushtimer src 9000 10
wait_for_blocked_clients_count 0
assert_equal {9000} [r fsl.getall dst]
assert_equal {} [r fsl.getall src]
assert_replication_stream $repl {
{select *}
{fsl.push src 9000}
{fsl.bpoppush src dst 0}
}
close_replication_stream $repl
} {} {needs:repl}
test {Module client blocked on keys (no metadata): No block} {
r del k
r fsl.push k 33
......@@ -303,4 +328,39 @@ start_server {tags {"modules"}} {
assert_equal {someval} [$rd read]
$rd close
}
set master [srv 0 client]
set master_host [srv 0 host]
set master_port [srv 0 port]
start_server [list overrides [list loadmodule "$testmodule"]] {
set replica [srv 0 client]
set replica_host [srv 0 host]
set replica_port [srv 0 port]
# Start the replication process...
$replica replicaof $master_host $master_port
wait_for_sync $replica
test {WAIT command on module blocked client on keys} {
set rd [redis_deferring_client -1]
$rd set x y
$rd read
pause_process [srv 0 pid]
$master del k
$rd fsl.bpop k 0
wait_for_blocked_client -1
$master fsl.push k 34
$master fsl.push k 35
assert_equal {34} [$rd read]
assert_equal [$master wait 1 1000] 0
resume_process [srv 0 pid]
assert_equal [$master wait 1 1000] 1
$rd close
assert_equal {35} [$replica fsl.getall k]
}
}
}
......@@ -139,5 +139,27 @@ test {Blocking Commands don't run through command filter when reprocessed} {
assert_equal [$rd read] 1
# validate that we moved the correct elements to the correct side of the list
assert_equal [r lpop list2{t}] 1
$rd close
}
}
test {Filtering based on client id} {
start_server {tags {"modules"}} {
r module load $testmodule log-key 0
set rr [redis_client]
set cid [$rr client id]
r unfilter_clientid $cid
r rpush mylist elem1 @replaceme elem2
assert_equal [r lrange mylist 0 -1] {elem1 --replaced-- elem2}
r del mylist
assert_equal [$rr rpush mylist elem1 @replaceme elem2] 3
assert_equal [r lrange mylist 0 -1] {elem1 @replaceme elem2}
$rr close
}
}
\ No newline at end of file
......@@ -89,4 +89,46 @@ start_server {tags {"modules"}} {
$rd read
$rd close
}
test {DataType: check the type name} {
r flushdb
r datatype.set foo 111 bar
assert_type test___dt foo
}
test {SCAN module datatype} {
r flushdb
populate 1000
r datatype.set foo 111 bar
set type [r type foo]
set cur 0
set keys {}
while 1 {
set res [r scan $cur type $type]
set cur [lindex $res 0]
set k [lindex $res 1]
lappend keys {*}$k
if {$cur == 0} break
}
assert_equal 1 [llength $keys]
}
test {SCAN module datatype with case sensitive} {
r flushdb
populate 1000
r datatype.set foo 111 bar
set type "tEsT___dT"
set cur 0
set keys {}
while 1 {
set res [r scan $cur type $type]
set cur [lindex $res 0]
set k [lindex $res 1]
lappend keys {*}$k
if {$cur == 0} break
}
assert_equal 1 [llength $keys]
}
}
......@@ -148,6 +148,19 @@ start_server {overrides {save {900 1}} tags {"modules"}} {
$rd_trk close
}
test {publish to self inside rm_call} {
r hello 3
r subscribe foo
# published message comes after the response of the command that issued it.
assert_equal [r test.rm_call publish foo bar] {1}
assert_equal [r read] {message foo bar}
r unsubscribe foo
r hello 2
set _ ""
} {} {resp3}
test {test module get/set client name by id api} {
catch { r test.getname } e
assert_equal "-ERR No name" $e
......
......@@ -13,5 +13,22 @@ start_server {tags {"modules"}} {
assert_equal 1 [r publish.classic chan1 world]
assert_equal {smessage chan1 hello} [$rd1 read]
assert_equal {message chan1 world} [$rd2 read]
$rd1 close
$rd2 close
}
test {module publish to self with multi message} {
r hello 3
r subscribe foo
# published message comes after the response of the command that issued it.
assert_equal [r publish.classic_multi foo bar vaz] {1 1}
assert_equal [r read] {message foo bar}
assert_equal [r read] {message foo vaz}
r unsubscribe foo
r hello 2
set _ ""
} {} {resp3}
}
......@@ -128,13 +128,19 @@ start_server {tags {"modules"}} {
test "RESP$proto: RM_ReplyWithErrorFormat: error format reply" {
catch {r rw.error_format "An error: %s" foo} e
assert_match "ERR An error: foo" $e
assert_match "An error: foo" $e ;# Should not be used by a user, but compatible with RM_ReplyError
catch {r rw.error_format "-ERR An error: %s" foo2} e
assert_match "ERR An error: foo2" $e
assert_match "-ERR An error: foo2" $e ;# Should not be used by a user, but compatible with RM_ReplyError (There are two hyphens, TCL removes the first one)
catch {r rw.error_format "-WRONGTYPE A type error: %s" foo3} e
assert_match "WRONGTYPE A type error: foo3" $e
assert_match "-WRONGTYPE A type error: foo3" $e ;# Should not be used by a user, but compatible with RM_ReplyError (There are two hyphens, TCL removes the first one)
catch {r rw.error_format "ERR An error: %s" foo4} e
assert_match "ERR An error: foo4" $e
catch {r rw.error_format "WRONGTYPE A type error: %s" foo5} e
assert_match "WRONGTYPE A type error: foo5" $e
}
r hello 2
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment