Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update server.call in the place of redis.call in test directory. #444

Open
wants to merge 2 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/cluster/tests/04-resharding.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ test "Cluster consistency during live resharding" {
} elseif {$listid % 3 == 1} {
$cluster_plaintext rpush $key $ele
} else {
$cluster eval {redis.call("rpush",KEYS[1],ARGV[1])} 1 $key $ele
$cluster eval {server.call("rpush",KEYS[1],ARGV[1])} 1 $key $ele
}
lappend content($key) $ele

Expand Down
8 changes: 4 additions & 4 deletions tests/integration/aof.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ tags {"aof external:skip"} {
# make sure that the script times out during loading
create_aof $aof_dirpath $aof_file {
append_to_aof [formatCommand select 9]
append_to_aof [formatCommand eval {redis.call('set',KEYS[1],'y'); for i=1,1500000 do redis.call('ping') end return 'ok'} 1 x]
append_to_aof [formatCommand eval {server.call('set',KEYS[1],'y'); for i=1,1500000 do server.call('ping') end return 'ok'} 1 x]
}
set rd [valkey_deferring_client]
$rd debug loadaof
Expand All @@ -460,9 +460,9 @@ tags {"aof external:skip"} {
}
create_aof $aof_dirpath $aof_file {
append_to_aof [formatCommand select 9]
append_to_aof [formatCommand eval {redis.call("set",KEYS[1],"100")} 1 foo]
append_to_aof [formatCommand eval {redis.call("incr",KEYS[1])} 1 foo]
append_to_aof [formatCommand eval {redis.call("incr",KEYS[1])} 1 foo]
append_to_aof [formatCommand eval {server.call("set",KEYS[1],"100")} 1 foo]
append_to_aof [formatCommand eval {server.call("incr",KEYS[1])} 1 foo]
append_to_aof [formatCommand eval {server.call("incr",KEYS[1])} 1 foo]
}
start_server [list overrides [list dir $server_path appendonly yes replica-read-only yes replicaof "127.0.0.1 0"]] {
assert_equal [r get foo] 102
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/rdb.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ start_server {overrides {save ""}} {

exec cp -f tests/assets/scriptbackup.rdb $server_path
start_server [list overrides [list "dir" $server_path "dbfilename" "scriptbackup.rdb" "appendonly" "no"]] {
# the script is: "return redis.call('set', 'foo', 'bar')""
# the script is: "return server.call('set', 'foo', 'bar')""
# its sha1 is: a0c38691e9fffe4563723c32ba77a34398e090e6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we need to also update the sha?

test {script won't load anymore if it's in rdb} {
assert_equal [r script exists a0c38691e9fffe4563723c32ba77a34398e090e6] 0
Expand Down Expand Up @@ -389,21 +389,21 @@ start_server {} {

# repeat with script
assert_error {MISCONF *} {r eval {
return redis.call('set','x',1)
return server.call('set','x',1)
} 1 x
}
assert_equal {x} [r eval {
return redis.call('get','x')
return server.call('get','x')
} 1 x
]

# again with script using shebang
assert_error {MISCONF *} {r eval {#!lua
return redis.call('set','x',1)
return server.call('set','x',1)
} 1 x
}
assert_equal {x} [r eval {#!lua flags=no-writes
return redis.call('get','x')
return server.call('get','x')
} 1 x
]

Expand Down
16 changes: 8 additions & 8 deletions tests/integration/replication-4.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ start_server {tags {"repl external:skip"}} {

# Load some functions to be used later
$master FUNCTION load replace {#!lua name=test
server.register_function{function_name='f_default_flags', callback=function(keys, args) return redis.call('get',keys[1]) end, flags={}}
server.register_function{function_name='f_no_writes', callback=function(keys, args) return redis.call('get',keys[1]) end, flags={'no-writes'}}
server.register_function{function_name='f_default_flags', callback=function(keys, args) return server.call('get',keys[1]) end, flags={}}
server.register_function{function_name='f_no_writes', callback=function(keys, args) return server.call('get',keys[1]) end, flags={'no-writes'}}
}

test {First server should have role slave after SLAVEOF} {
Expand All @@ -74,14 +74,14 @@ start_server {tags {"repl external:skip"}} {
$master config set min-slaves-max-lag 3
$master config set min-slaves-to-write 1
assert_equal OK [$master set foo 123]
assert_equal OK [$master eval "return redis.call('set','foo',12345)" 0]
assert_equal OK [$master eval "return server.call('set','foo',12345)" 0]
}

test {With min-slaves-to-write (2,3): master should not be writable} {
$master config set min-slaves-max-lag 3
$master config set min-slaves-to-write 2
assert_error "*NOREPLICAS*" {$master set foo bar}
assert_error "*NOREPLICAS*" {$master eval "redis.call('set','foo','bar')" 0}
assert_error "*NOREPLICAS*" {$master eval "server.call('set','foo','bar')" 0}
}

test {With min-slaves-to-write function without no-write flag} {
Expand All @@ -92,17 +92,17 @@ start_server {tags {"repl external:skip"}} {
test {With not enough good slaves, read in Lua script is still accepted} {
$master config set min-slaves-max-lag 3
$master config set min-slaves-to-write 1
$master eval "redis.call('set','foo','bar')" 0
$master eval "server.call('set','foo','bar')" 0

$master config set min-slaves-to-write 2
$master eval "return redis.call('get','foo')" 0
$master eval "return server.call('get','foo')" 0
} {bar}

test {With min-slaves-to-write: master not writable with lagged slave} {
$master config set min-slaves-max-lag 2
$master config set min-slaves-to-write 1
assert_equal OK [$master set foo 123]
assert_equal OK [$master eval "return redis.call('set','foo',12345)" 0]
assert_equal OK [$master eval "return server.call('set','foo',12345)" 0]
# Killing a slave to make it become a lagged slave.
pause_process [srv 0 pid]
# Waiting for slave kill.
Expand All @@ -112,7 +112,7 @@ start_server {tags {"repl external:skip"}} {
fail "Master didn't become readonly"
}
assert_error "*NOREPLICAS*" {$master set foo 123}
assert_error "*NOREPLICAS*" {$master eval "return redis.call('set','foo',12345)" 0}
assert_error "*NOREPLICAS*" {$master eval "return server.call('set','foo',12345)" 0}
resume_process [srv 0 pid]
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/replication.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ start_server {tags {"repl external:skip"}} {
# DB is empty.
r -1 flushdb
r -1 flushdb
r -1 eval {redis.call("flushdb")} 0
r -1 eval {server.call("flushdb")} 0

# DBs are empty.
r -1 flushall
r -1 flushall
r -1 eval {redis.call("flushall")} 0
r -1 eval {server.call("flushall")} 0

# add another command to check nothing else was propagated after the above
r -1 incr x
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/propagate.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void timerHandlerEval(ValkeyModuleCtx *ctx, void *data) {

ValkeyModuleCallReply *reply = ValkeyModule_Call(ctx,"INCRBY","cc!","timer-eval-start","1");
ValkeyModule_FreeCallReply(reply);
reply = ValkeyModule_Call(ctx, "EVAL", "cccc!", "redis.call('set',KEYS[1],ARGV[1])", "1", "foo", "bar");
reply = ValkeyModule_Call(ctx, "EVAL", "cccc!", "server.call('set',KEYS[1],ARGV[1])", "1", "foo", "bar");
ValkeyModule_FreeCallReply(reply);

ValkeyModule_Replicate(ctx, "INCR", "c", "timer-eval-middle");
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/acl.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ start_server {tags {"acl external:skip"}} {

test {ACL can log errors in the context of Lua scripting} {
r AUTH antirez foo
catch {r EVAL {redis.call('incr','foo')} 0}
catch {r EVAL {server.call('incr','foo')} 0}
r AUTH default ""
set entry [lindex [r ACL LOG] 0]
assert {[dict get $entry context] eq {lua}}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/client-eviction.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ start_server {} {
set key_length [expr 1024*200]
set long_key [string repeat k $key_length]
# Use a script so we won't need to pass the long key name when dirtying it in the loop
set script_sha [$rr script load "redis.call('incr', '$long_key')"]
set script_sha [$rr script load "server.call('incr', '$long_key')"]

# Pause serverCron so it won't update memory usage since we're testing the update logic when
# writing tracking redirection output
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/cluster/scripting.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ start_cluster 1 0 {tags {external:skip cluster}} {
# Test that scripts with shebang block cross slot operations
assert_error "ERR Script attempted to access keys that do not hash to the same slot*" {
r 0 eval {#!lua
redis.call('set', 'foo', 'bar')
redis.call('set', 'bar', 'foo')
server.call('set', 'foo', 'bar')
server.call('set', 'bar', 'foo')
return 'OK'
} 0}

# Test the functions by default block cross slot operations
r 0 function load REPLACE {#!lua name=crossslot
local function test_cross_slot(keys, args)
redis.call('set', 'foo', 'bar')
redis.call('set', 'bar', 'foo')
server.call('set', 'foo', 'bar')
server.call('set', 'bar', 'foo')
return 'OK'
end

Expand All @@ -23,11 +23,11 @@ start_cluster 1 0 {tags {external:skip cluster}} {

test {Cross slot commands are allowed by default for eval scripts and with allow-cross-slot-keys flag} {
# Old style lua scripts are allowed to access cross slot operations
r 0 eval "redis.call('set', 'foo', 'bar'); redis.call('set', 'bar', 'foo')" 0
r 0 eval "server.call('set', 'foo', 'bar'); server.call('set', 'bar', 'foo')" 0

# scripts with allow-cross-slot-keys flag are allowed
r 0 eval {#!lua flags=allow-cross-slot-keys
redis.call('set', 'foo', 'bar'); redis.call('set', 'bar', 'foo')
server.call('set', 'foo', 'bar'); server.call('set', 'bar', 'foo')
} 0

# Retrieve data from different slot to verify data has been stored in the correct dictionary in cluster-enabled setup
Expand All @@ -40,8 +40,8 @@ start_cluster 1 0 {tags {external:skip cluster}} {
# Functions with allow-cross-slot-keys flag are allowed
r 0 function load REPLACE {#!lua name=crossslot
local function test_cross_slot(keys, args)
redis.call('set', 'foo', 'bar')
redis.call('set', 'bar', 'foo')
server.call('set', 'foo', 'bar')
server.call('set', 'bar', 'foo')
return 'OK'
end

Expand All @@ -57,14 +57,14 @@ start_cluster 1 0 {tags {external:skip cluster}} {
test {Cross slot commands are also blocked if they disagree with pre-declared keys} {
assert_error "ERR Script attempted to access keys that do not hash to the same slot*" {
r 0 eval {#!lua
redis.call('set', 'foo', 'bar')
server.call('set', 'foo', 'bar')
return 'OK'
} 1 bar}
}

test {Cross slot commands are allowed by default if they disagree with pre-declared keys} {
r 0 flushall
r 0 eval "redis.call('set', 'foo', 'bar')" 1 bar
r 0 eval "server.call('set', 'foo', 'bar')" 1 bar

# Make sure the script writes to the right slot
assert_equal 1 [r 0 cluster COUNTKEYSINSLOT 12182] ;# foo slot
Expand Down
32 changes: 16 additions & 16 deletions tests/unit/functions.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ start_server {tags {"scripting"}} {

test {FUNCTION - test flushall and flushdb do not clean functions} {
r function flush
r function load REPLACE [get_function_code lua test test {return redis.call('set', 'x', '1')}]
r function load REPLACE [get_function_code lua test test {return server.call('set', 'x', '1')}]
r flushall
r flushdb
r function list
Expand Down Expand Up @@ -209,19 +209,19 @@ start_server {tags {"scripting"}} {
} {*unknown subcommand or wrong number of arguments for 'restore'. Try FUNCTION HELP.}

test {FUNCTION - test fcall_ro with write command} {
r function load REPLACE [get_no_writes_function_code lua test test {return redis.call('set', 'x', '1')}]
r function load REPLACE [get_no_writes_function_code lua test test {return server.call('set', 'x', '1')}]
catch { r fcall_ro test 1 x } e
set _ $e
} {*Write commands are not allowed from read-only scripts*}

test {FUNCTION - test fcall_ro with read only commands} {
r function load REPLACE [get_no_writes_function_code lua test test {return redis.call('get', 'x')}]
r function load REPLACE [get_no_writes_function_code lua test test {return server.call('get', 'x')}]
r set x 1
r fcall_ro test 1 x
} {1}

test {FUNCTION - test keys and argv} {
r function load REPLACE [get_function_code lua test test {return redis.call('set', KEYS[1], ARGV[1])}]
r function load REPLACE [get_function_code lua test test {return server.call('set', KEYS[1], ARGV[1])}]
r fcall test 1 x foo
r get x
} {foo}
Expand Down Expand Up @@ -410,7 +410,7 @@ start_server {tags {"scripting repl external:skip"}} {
} {*can't write against a read only replica*}

test "FUNCTION - function effect is replicated to replica" {
r function load REPLACE [get_function_code LUA test test {return redis.call('set', 'x', '1')}]
r function load REPLACE [get_function_code LUA test test {return server.call('set', 'x', '1')}]
r fcall test 1 x
assert {[r get x] eq {1}}
wait_for_condition 150 100 {
Expand Down Expand Up @@ -461,7 +461,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - test shared function can access default globals} {
r function load {#!lua name=lib1
local function ping()
return redis.call('ping')
return server.call('ping')
end
server.register_function(
'f1',
Expand Down Expand Up @@ -618,10 +618,10 @@ start_server {tags {"scripting"}} {
set _ $e
} {*attempted to access nonexistent global variable 'math'*}

test {LIBRARIES - redis.call from function load} {
test {LIBRARIES - server.call from function load} {
catch {
r function load replace {#!lua name=lib2
return redis.call('ping')
return server.call('ping')
}
} e
set _ $e
Expand Down Expand Up @@ -688,9 +688,9 @@ start_server {tags {"scripting"}} {
assert_match {*Script attempted to access nonexistent global variable 'math'*} $e

catch {[r function load {#!lua name=lib2
redis.redis.call('ping')
redis.server.call('ping')
}]} e
assert_match {*Script attempted to access nonexistent global variable 'redis'*} $e
assert_match {*Script attempted to access nonexistent global variable 'server'*} $e

catch {[r fcall f2 0]} e
assert_match {*can only be called on FUNCTION LOAD command*} $e
Expand Down Expand Up @@ -983,7 +983,7 @@ start_server {tags {"scripting"}} {
r FUNCTION load replace {#!lua name=f1
server.register_function{
function_name='f1',
callback=function() return redis.call('set', 'x', '1') end,
callback=function() return server.call('set', 'x', '1') end,
flags={'allow-oom'}
}
}
Expand Down Expand Up @@ -1035,7 +1035,7 @@ start_server {tags {"scripting"}} {
r function load replace {#!lua name=test
server.register_function{
function_name = 'f1',
callback = function() return redis.call('set', 'x', 1) end
callback = function() return server.call('set', 'x', 1) end
}
}
catch {r fcall_ro f1 1 x} e
Expand All @@ -1046,7 +1046,7 @@ start_server {tags {"scripting"}} {
r function load replace {#!lua name=test
server.register_function{
function_name = 'f1',
callback = function() return redis.call('set', 'x', 1) end,
callback = function() return server.call('set', 'x', 1) end,
flags = {'no-writes'}
}
}
Expand All @@ -1056,7 +1056,7 @@ start_server {tags {"scripting"}} {

test {FUNCTION - deny oom} {
r FUNCTION load replace {#!lua name=test
server.register_function('f1', function() return redis.call('set', 'x', '1') end)
server.register_function('f1', function() return server.call('set', 'x', '1') end)
}

r config set maxmemory 1
Expand Down Expand Up @@ -1084,8 +1084,8 @@ start_server {tags {"scripting"}} {
r FUNCTION load replace {#!lua name=test
server.register_function{function_name='f1', callback=function() return 'hello' end, flags={'no-writes'}}
server.register_function{function_name='f2', callback=function() return 'hello' end, flags={'allow-stale', 'no-writes'}}
server.register_function{function_name='f3', callback=function() return redis.call('get', 'x') end, flags={'allow-stale', 'no-writes'}}
server.register_function{function_name='f4', callback=function() return redis.call('info', 'server') end, flags={'allow-stale', 'no-writes'}}
server.register_function{function_name='f3', callback=function() return server.call('get', 'x') end, flags={'allow-stale', 'no-writes'}}
server.register_function{function_name='f4', callback=function() return server.call('info', 'server') end, flags={'allow-stale', 'no-writes'}}
}

r config set replica-serve-stale-data no
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/introspection-2.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ start_server {tags {"introspection"}} {
r config resetstat
r set mykey myval
r eval {
redis.call('set', KEYS[1], 0)
redis.call('expire', KEYS[1], 0)
redis.call('geoadd', KEYS[1], 0, 0, "bar")
server.call('set', KEYS[1], 0)
server.call('expire', KEYS[1], 0)
server.call('geoadd', KEYS[1], 0, 0, "bar")
} 1 mykey
assert_match {*calls=1,*} [cmdstat eval]
assert_match {*calls=2,*} [cmdstat set]
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/introspection.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ start_server {tags {"introspection"}} {
set rd [valkey_deferring_client]
$rd monitor
$rd read ;# Discard the OK
r eval {redis.call('set',KEYS[1],ARGV[1])} 1 foo bar
r eval {server.call('set',KEYS[1],ARGV[1])} 1 foo bar
assert_match {*eval*} [$rd read]
assert_match {*lua*"set"*"foo"*"bar"*} [$rd read]
$rd close
}

test {MONITOR can log commands issued by functions} {
r function load replace {#!lua name=test
server.register_function('test', function() return redis.call('set', 'foo', 'bar') end)
server.register_function('test', function() return server.call('set', 'foo', 'bar') end)
}
set rd [valkey_deferring_client]
$rd monitor
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/latency-monitor.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ tags {"needs:debug"} {
r eval {
local i = 0
while (i < tonumber(ARGV[1])) do
redis.call('sadd',KEYS[1],i)
server.call('sadd',KEYS[1],i)
i = i+1
end
} 1 mybigkey $count
Expand Down
Loading
Loading