summaryrefslogtreecommitdiff
path: root/tests/unit/functions.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/functions.tcl')
-rw-r--r--tests/unit/functions.tcl348
1 files changed, 207 insertions, 141 deletions
diff --git a/tests/unit/functions.tcl b/tests/unit/functions.tcl
index 65e99e9e7..4c08261ed 100644
--- a/tests/unit/functions.tcl
+++ b/tests/unit/functions.tcl
@@ -1,61 +1,61 @@
proc get_function_code {args} {
- return [format "redis.register_function('%s', function(KEYS, ARGV)\n %s \nend)" [lindex $args 0] [lindex $args 1]]
+ return [format "#!%s name=%s\nredis.register_function('%s', function(KEYS, ARGV)\n %s \nend)" [lindex $args 0] [lindex $args 1] [lindex $args 2] [lindex $args 3]]
}
proc get_no_writes_function_code {args} {
- return [format "redis.register_function{function_name='%s', callback=function(KEYS, ARGV)\n %s \nend, flags={'no-writes'}}" [lindex $args 0] [lindex $args 1]]
+ return [format "#!%s name=%s\nredis.register_function{function_name='%s', callback=function(KEYS, ARGV)\n %s \nend, flags={'no-writes'}}" [lindex $args 0] [lindex $args 1] [lindex $args 2] [lindex $args 3]]
}
start_server {tags {"scripting"}} {
test {FUNCTION - Basic usage} {
- r function load LUA test [get_function_code test {return 'hello'}]
+ r function load [get_function_code LUA test test {return 'hello'}]
r fcall test 0
} {hello}
test {FUNCTION - Load with unknown argument} {
catch {
- r function load LUA test foo bar [get_function_code test {return 'hello'}]
+ r function load foo bar [get_function_code LUA test test {return 'hello'}]
} e
set _ $e
} {*Unknown option given*}
test {FUNCTION - Create an already exiting library raise error} {
catch {
- r function load LUA test [get_function_code test {return 'hello1'}]
+ r function load [get_function_code LUA test test {return 'hello1'}]
} e
set _ $e
} {*already exists*}
test {FUNCTION - Create an already exiting library raise error (case insensitive)} {
catch {
- r function load LUA TEST [get_function_code test {return 'hello1'}]
+ r function load [get_function_code LUA test test {return 'hello1'}]
} e
set _ $e
} {*already exists*}
test {FUNCTION - Create a library with wrong name format} {
catch {
- r function load LUA {bad\0foramat} [get_function_code test {return 'hello1'}]
+ r function load [get_function_code LUA {bad\0foramat} test {return 'hello1'}]
} e
set _ $e
} {*Library names can only contain letters and numbers*}
test {FUNCTION - Create library with unexisting engine} {
catch {
- r function load bad_engine test [get_function_code test {return 'hello1'}]
+ r function load [get_function_code bad_engine test test {return 'hello1'}]
} e
set _ $e
- } {*Engine not found*}
+ } {*Engine 'bad_engine' not found*}
test {FUNCTION - Test uncompiled script} {
catch {
- r function load LUA test1 {bad script}
+ r function load replace [get_function_code LUA test test {bad script}]
} e
set _ $e
} {*Error compiling function*}
test {FUNCTION - test replace argument} {
- r function load LUA test REPLACE [get_function_code test {return 'hello1'}]
+ r function load REPLACE [get_function_code LUA test test {return 'hello1'}]
r fcall test 0
} {hello1}
@@ -76,12 +76,8 @@ start_server {tags {"scripting"}} {
set _ $e
} {*Function not found*}
- test {FUNCTION - test description argument} {
- r function load LUA test DESCRIPTION {some description} [get_function_code test {return 'hello'}]
- r function list
- } {{library_name test engine LUA description {some description} functions {{name test description {} flags {}}}}}
-
test {FUNCTION - test fcall bad arguments} {
+ r function load [get_function_code LUA test test {return 'hello'}]
catch {
r fcall test bad_arg
} e
@@ -133,14 +129,14 @@ start_server {tags {"scripting"}} {
assert_match "*Error trying to load the RDB*" $e
r debug reload noflush merge
r function list
- } {{library_name test engine LUA description {some description} functions {{name test description {} flags {}}}}} {needs:debug}
+ } {{library_name test engine LUA functions {{name test description {} flags {}}}}} {needs:debug}
test {FUNCTION - test debug reload with nosave and noflush} {
r function delete test
r set x 1
- r function load LUA test1 DESCRIPTION {some description} [get_function_code test1 {return 'hello'}]
+ r function load [get_function_code LUA test1 test1 {return 'hello'}]
r debug reload
- r function load LUA test2 DESCRIPTION {some description} [get_function_code test2 {return 'hello'}]
+ r function load [get_function_code LUA test2 test2 {return 'hello'}]
r debug reload nosave noflush merge
assert_equal [r fcall test1 0] {hello}
assert_equal [r fcall test2 0] {hello}
@@ -148,21 +144,21 @@ start_server {tags {"scripting"}} {
test {FUNCTION - test flushall and flushdb do not clean functions} {
r function flush
- r function load lua test REPLACE [get_function_code test {return redis.call('set', 'x', '1')}]
+ r function load REPLACE [get_function_code lua test test {return redis.call('set', 'x', '1')}]
r flushall
r flushdb
r function list
- } {{library_name test engine LUA description {} functions {{name test description {} flags {}}}}}
+ } {{library_name test engine LUA functions {{name test description {} flags {}}}}}
test {FUNCTION - test function dump and restore} {
r function flush
- r function load lua test description {some description} [get_function_code test {return 'hello'}]
+ r function load [get_function_code lua test test {return 'hello'}]
set e [r function dump]
r function delete test
assert_match {} [r function list]
r function restore $e
r function list
- } {{library_name test engine LUA description {some description} functions {{name test description {} flags {}}}}}
+ } {{library_name test engine LUA functions {{name test description {} flags {}}}}}
test {FUNCTION - test function dump and restore with flush argument} {
set e [r function dump]
@@ -170,17 +166,17 @@ start_server {tags {"scripting"}} {
assert_match {} [r function list]
r function restore $e FLUSH
r function list
- } {{library_name test engine LUA description {some description} functions {{name test description {} flags {}}}}}
+ } {{library_name test engine LUA functions {{name test description {} flags {}}}}}
test {FUNCTION - test function dump and restore with append argument} {
set e [r function dump]
r function flush
assert_match {} [r function list]
- r function load lua test [get_function_code test {return 'hello1'}]
+ r function load [get_function_code lua test test {return 'hello1'}]
catch {r function restore $e APPEND} err
assert_match {*already exists*} $err
r function flush
- r function load lua test1 [get_function_code test1 {return 'hello1'}]
+ r function load [get_function_code lua test1 test1 {return 'hello1'}]
r function restore $e APPEND
assert_match {hello} [r fcall test 0]
assert_match {hello1} [r fcall test1 0]
@@ -188,11 +184,11 @@ start_server {tags {"scripting"}} {
test {FUNCTION - test function dump and restore with replace argument} {
r function flush
- r function load LUA test DESCRIPTION {some description} [get_function_code test {return 'hello'}]
+ r function load [get_function_code LUA test test {return 'hello'}]
set e [r function dump]
r function flush
assert_match {} [r function list]
- r function load lua test [get_function_code test {return 'hello1'}]
+ r function load [get_function_code lua test test {return 'hello1'}]
assert_match {hello1} [r fcall test 0]
r function restore $e REPLACE
assert_match {hello} [r fcall test 0]
@@ -200,11 +196,11 @@ start_server {tags {"scripting"}} {
test {FUNCTION - test function restore with bad payload do not drop existing functions} {
r function flush
- r function load LUA test DESCRIPTION {some description} [get_function_code test {return 'hello'}]
+ r function load [get_function_code LUA test test {return 'hello'}]
catch {r function restore bad_payload} e
assert_match {*payload version or checksum are wrong*} $e
r function list
- } {{library_name test engine LUA description {some description} functions {{name test description {} flags {}}}}}
+ } {{library_name test engine LUA functions {{name test description {} flags {}}}}}
test {FUNCTION - test function restore with wrong number of arguments} {
catch {r function restore arg1 args2 arg3} e
@@ -212,19 +208,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 lua test REPLACE [get_no_writes_function_code test {return redis.call('set', 'x', '1')}]
+ r function load REPLACE [get_no_writes_function_code lua test test {return redis.call('set', 'x', '1')}]
catch { r fcall_ro test 0 } e
set _ $e
} {*Write commands are not allowed from read-only scripts*}
test {FUNCTION - test fcall_ro with read only commands} {
- r function load lua test REPLACE [get_no_writes_function_code test {return redis.call('get', 'x')}]
+ r function load REPLACE [get_no_writes_function_code lua test test {return redis.call('get', 'x')}]
r set x 1
r fcall_ro test 0
} {1}
test {FUNCTION - test keys and argv} {
- r function load lua test REPLACE [get_function_code test {return redis.call('set', KEYS[1], ARGV[1])}]
+ r function load REPLACE [get_function_code lua test test {return redis.call('set', KEYS[1], ARGV[1])}]
r fcall test 1 x foo
r get x
} {foo}
@@ -240,7 +236,7 @@ start_server {tags {"scripting"}} {
test {FUNCTION - test function kill} {
set rd [redis_deferring_client]
r config set busy-reply-threshold 10
- r function load lua test REPLACE [get_function_code test {local a = 1 while true do a = a + 1 end}]
+ r function load REPLACE [get_function_code lua test test {local a = 1 while true do a = a + 1 end}]
$rd fcall test 0
after 200
catch {r ping} e
@@ -254,7 +250,7 @@ start_server {tags {"scripting"}} {
test {FUNCTION - test script kill not working on function} {
set rd [redis_deferring_client]
r config set busy-reply-threshold 10
- r function load lua test REPLACE [get_function_code test {local a = 1 while true do a = a + 1 end}]
+ r function load REPLACE [get_function_code lua test test {local a = 1 while true do a = a + 1 end}]
$rd fcall test 0
after 200
catch {r ping} e
@@ -281,18 +277,18 @@ start_server {tags {"scripting"}} {
}
test {FUNCTION - test function flush} {
- r function load lua test REPLACE [get_function_code test {local a = 1 while true do a = a + 1 end}]
- assert_match {{library_name test engine LUA description {} functions {{name test description {} flags {}}}}} [r function list]
+ r function load REPLACE [get_function_code lua test test {local a = 1 while true do a = a + 1 end}]
+ assert_match {{library_name test engine LUA functions {{name test description {} flags {}}}}} [r function list]
r function flush
assert_match {} [r function list]
- r function load lua test REPLACE [get_function_code test {local a = 1 while true do a = a + 1 end}]
- assert_match {{library_name test engine LUA description {} functions {{name test description {} flags {}}}}} [r function list]
+ r function load REPLACE [get_function_code lua test test {local a = 1 while true do a = a + 1 end}]
+ assert_match {{library_name test engine LUA functions {{name test description {} flags {}}}}} [r function list]
r function flush async
assert_match {} [r function list]
- r function load lua test REPLACE [get_function_code test {local a = 1 while true do a = a + 1 end}]
- assert_match {{library_name test engine LUA description {} functions {{name test description {} flags {}}}}} [r function list]
+ r function load REPLACE [get_function_code lua test test {local a = 1 while true do a = a + 1 end}]
+ assert_match {{library_name test engine LUA functions {{name test description {} flags {}}}}} [r function list]
r function flush sync
assert_match {} [r function list]
}
@@ -310,7 +306,7 @@ start_server {tags {"scripting repl external:skip"}} {
start_server {} {
test "Connect a replica to the master instance" {
r -1 slaveof [srv 0 host] [srv 0 port]
- wait_for_condition 50 100 {
+ wait_for_condition 150 100 {
[s -1 role] eq {slave} &&
[string match {*master_link_status:up*} [r -1 info replication]]
} else {
@@ -319,9 +315,9 @@ start_server {tags {"scripting repl external:skip"}} {
}
test {FUNCTION - creation is replicated to replica} {
- r function load LUA test DESCRIPTION {some description} [get_no_writes_function_code test {return 'hello'}]
- wait_for_condition 50 100 {
- [r -1 function list] eq {{library_name test engine LUA description {some description} functions {{name test description {} flags no-writes}}}}
+ r function load [get_no_writes_function_code LUA test test {return 'hello'}]
+ wait_for_condition 150 100 {
+ [r -1 function list] eq {{library_name test engine LUA functions {{name test description {} flags no-writes}}}}
} else {
fail "Failed waiting for function to replicate to replica"
}
@@ -335,7 +331,7 @@ start_server {tags {"scripting repl external:skip"}} {
set e [r function dump]
r function delete test
- wait_for_condition 50 100 {
+ wait_for_condition 150 100 {
[r -1 function list] eq {}
} else {
fail "Failed waiting for function to replicate to replica"
@@ -343,8 +339,8 @@ start_server {tags {"scripting repl external:skip"}} {
assert_equal [r function restore $e] {OK}
- wait_for_condition 50 100 {
- [r -1 function list] eq {{library_name test engine LUA description {some description} functions {{name test description {} flags no-writes}}}}
+ wait_for_condition 150 100 {
+ [r -1 function list] eq {{library_name test engine LUA functions {{name test description {} flags no-writes}}}}
} else {
fail "Failed waiting for function to replicate to replica"
}
@@ -352,7 +348,7 @@ start_server {tags {"scripting repl external:skip"}} {
test {FUNCTION - delete is replicated to replica} {
r function delete test
- wait_for_condition 50 100 {
+ wait_for_condition 150 100 {
[r -1 function list] eq {}
} else {
fail "Failed waiting for function to replicate to replica"
@@ -360,14 +356,14 @@ start_server {tags {"scripting repl external:skip"}} {
}
test {FUNCTION - flush is replicated to replica} {
- r function load LUA test DESCRIPTION {some description} [get_function_code test {return 'hello'}]
- wait_for_condition 50 100 {
- [r -1 function list] eq {{library_name test engine LUA description {some description} functions {{name test description {} flags {}}}}}
+ r function load [get_function_code LUA test test {return 'hello'}]
+ wait_for_condition 150 100 {
+ [r -1 function list] eq {{library_name test engine LUA functions {{name test description {} flags {}}}}}
} else {
fail "Failed waiting for function to replicate to replica"
}
r function flush
- wait_for_condition 50 100 {
+ wait_for_condition 150 100 {
[r -1 function list] eq {}
} else {
fail "Failed waiting for function to replicate to replica"
@@ -378,11 +374,11 @@ start_server {tags {"scripting repl external:skip"}} {
r -1 slaveof no one
# creating a function after disconnect to make sure function
# is replicated on rdb phase
- r function load LUA test DESCRIPTION {some description} [get_no_writes_function_code test {return 'hello'}]
+ r function load [get_no_writes_function_code LUA test test {return 'hello'}]
# reconnect the replica
r -1 slaveof [srv 0 host] [srv 0 port]
- wait_for_condition 50 100 {
+ wait_for_condition 150 100 {
[s -1 role] eq {slave} &&
[string match {*master_link_status:up*} [r -1 info replication]]
} else {
@@ -396,11 +392,11 @@ start_server {tags {"scripting repl external:skip"}} {
test "FUNCTION - test replication to replica on rdb phase info command" {
r -1 function list
- } {{library_name test engine LUA description {some description} functions {{name test description {} flags no-writes}}}}
+ } {{library_name test engine LUA functions {{name test description {} flags no-writes}}}}
test "FUNCTION - create on read only replica" {
catch {
- r -1 function load LUA test DESCRIPTION {some description} [get_function_code test {return 'hello'}]
+ r -1 function load [get_function_code LUA test test {return 'hello'}]
} e
set _ $e
} {*can't write against a read only replica*}
@@ -413,10 +409,10 @@ 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 LUA test REPLACE [get_function_code test {return redis.call('set', 'x', '1')}]
+ r function load REPLACE [get_function_code LUA test test {return redis.call('set', 'x', '1')}]
r fcall test 0
assert {[r get x] eq {1}}
- wait_for_condition 50 100 {
+ wait_for_condition 150 100 {
[r -1 get x] eq {1}
} else {
fail "Failed waiting function effect to be replicated to replica"
@@ -436,12 +432,12 @@ test {FUNCTION can processes create, delete and flush commands in AOF when doing
start_server {} {
r config set appendonly yes
waitForBgrewriteaof r
- r FUNCTION LOAD lua test "redis.register_function('test', function() return 'hello' end)"
+ r FUNCTION LOAD "#!lua name=test\nredis.register_function('test', function() return 'hello' end)"
r config set slave-read-only yes
r slaveof 127.0.0.1 0
r debug loadaof
r slaveof no one
- assert_equal [r function list] {{library_name test engine LUA description {} functions {{name test description {} flags {}}}}}
+ assert_equal [r function list] {{library_name test engine LUA functions {{name test description {} flags {}}}}}
r FUNCTION DELETE test
@@ -450,7 +446,7 @@ test {FUNCTION can processes create, delete and flush commands in AOF when doing
r slaveof no one
assert_equal [r function list] {}
- r FUNCTION LOAD lua test "redis.register_function('test', function() return 'hello' end)"
+ r FUNCTION LOAD "#!lua name=test\nredis.register_function('test', function() return 'hello' end)"
r FUNCTION FLUSH
r slaveof 127.0.0.1 0
@@ -462,7 +458,7 @@ test {FUNCTION can processes create, delete and flush commands in AOF when doing
start_server {tags {"scripting"}} {
test {LIBRARIES - test shared function can access default globals} {
- r function load LUA lib1 {
+ r function load {#!lua name=lib1
local function ping()
return redis.call('ping')
end
@@ -477,7 +473,7 @@ start_server {tags {"scripting"}} {
} {PONG}
test {LIBRARIES - usage and code sharing} {
- r function load LUA lib1 REPLACE {
+ r function load REPLACE {#!lua name=lib1
local function add1(a)
return a + 1
end
@@ -497,11 +493,11 @@ start_server {tags {"scripting"}} {
assert_equal [r fcall f1 0] {2}
assert_equal [r fcall f2 0] {3}
r function list
- } {{library_name lib1 engine LUA description {} functions {*}}}
+ } {{library_name lib1 engine LUA functions {*}}}
test {LIBRARIES - test registration failure revert the entire load} {
catch {
- r function load LUA lib1 replace {
+ r function load replace {#!lua name=lib1
local function add1(a)
return a + 2
end
@@ -524,7 +520,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - test registration function name collision} {
catch {
- r function load LUA lib2 replace {
+ r function load replace {#!lua name=lib2
redis.register_function(
'f1',
function(keys, args)
@@ -540,7 +536,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - test registration function name collision on same library} {
catch {
- r function load LUA lib2 replace {
+ r function load replace {#!lua name=lib2
redis.register_function(
'f1',
function(keys, args)
@@ -560,7 +556,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - test registration with no argument} {
catch {
- r function load LUA lib2 replace {
+ r function load replace {#!lua name=lib2
redis.register_function()
}
} e
@@ -569,7 +565,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - test registration with only name} {
catch {
- r function load LUA lib2 replace {
+ r function load replace {#!lua name=lib2
redis.register_function('f1')
}
} e
@@ -578,7 +574,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - test registration with to many arguments} {
catch {
- r function load LUA lib2 replace {
+ r function load replace {#!lua name=lib2
redis.register_function('f1', function() return 1 end, {}, 'description', 'extra arg')
}
} e
@@ -587,7 +583,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - test registration with no string name} {
catch {
- r function load LUA lib2 replace {
+ r function load replace {#!lua name=lib2
redis.register_function(nil, function() return 1 end)
}
} e
@@ -596,7 +592,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - test registration with wrong name format} {
catch {
- r function load LUA lib2 replace {
+ r function load replace {#!lua name=lib2
redis.register_function('test\0test', function() return 1 end)
}
} e
@@ -605,7 +601,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - test registration with empty name} {
catch {
- r function load LUA lib2 replace {
+ r function load replace {#!lua name=lib2
redis.register_function('', function() return 1 end)
}
} e
@@ -614,7 +610,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - math.random from function load} {
catch {
- r function load LUA lib2 replace {
+ r function load replace {#!lua name=lib2
return math.random()
}
} e
@@ -623,7 +619,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - redis.call from function load} {
catch {
- r function load LUA lib2 replace {
+ r function load replace {#!lua name=lib2
return redis.call('ping')
}
} e
@@ -632,7 +628,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - redis.call from function load} {
catch {
- r function load LUA lib2 replace {
+ r function load replace {#!lua name=lib2
return redis.setresp(3)
}
} e
@@ -641,7 +637,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - redis.set_repl from function load} {
catch {
- r function load LUA lib2 replace {
+ r function load replace {#!lua name=lib2
return redis.set_repl(redis.REPL_NONE)
}
} e
@@ -657,7 +653,7 @@ start_server {tags {"scripting"}} {
# have another level of protection on the C
# code itself and we want to test it and verify
# that it works properly.
- r function load LUA lib1 replace {
+ r function load replace {#!lua name=lib1
local lib = redis
lib.register_function('f1', function ()
lib.redis = redis
@@ -675,22 +671,34 @@ start_server {tags {"scripting"}} {
}
assert_equal {OK} [r fcall f1 0]
- catch {[r function load LUA lib2 {redis.math.random()}]} e
+ catch {[r function load {#!lua name=lib2
+ redis.math.random()
+ }]} e
assert_match {*can only be called inside a script invocation*} $e
- catch {[r function load LUA lib2 {redis.math.randomseed()}]} e
+ catch {[r function load {#!lua name=lib2
+ redis.math.randomseed()
+ }]} e
assert_match {*can only be called inside a script invocation*} $e
- catch {[r function load LUA lib2 {redis.redis.call('ping')}]} e
+ catch {[r function load {#!lua name=lib2
+ redis.redis.call('ping')
+ }]} e
assert_match {*can only be called inside a script invocation*} $e
- catch {[r function load LUA lib2 {redis.redis.pcall('ping')}]} e
+ catch {[r function load {#!lua name=lib2
+ redis.redis.pcall('ping')
+ }]} e
assert_match {*can only be called inside a script invocation*} $e
- catch {[r function load LUA lib2 {redis.redis.setresp(3)}]} e
+ catch {[r function load {#!lua name=lib2
+ redis.redis.setresp(3)
+ }]} e
assert_match {*can only be called inside a script invocation*} $e
- catch {[r function load LUA lib2 {redis.redis.set_repl(redis.redis.REPL_NONE)}]} e
+ catch {[r function load {#!lua name=lib2
+ redis.redis.set_repl(redis.redis.REPL_NONE)
+ }]} e
assert_match {*can only be called inside a script invocation*} $e
catch {[r fcall f2 0]} e
@@ -703,7 +711,7 @@ start_server {tags {"scripting"}} {
} {}
test {LIBRARIES - register function inside a function} {
- r function load LUA lib {
+ r function load {#!lua name=lib
redis.register_function(
'f1',
function(keys, args)
@@ -724,7 +732,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - register library with no functions} {
r function flush
catch {
- r function load LUA lib {
+ r function load {#!lua name=lib
return 1
}
} e
@@ -733,7 +741,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - load timeout} {
catch {
- r function load LUA lib {
+ r function load {#!lua name=lib
local a = 1
while 1 do a = a + 1 end
}
@@ -743,7 +751,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - verify global protection on the load run} {
catch {
- r function load LUA lib {
+ r function load {#!lua name=lib
a = 1
}
} e
@@ -751,7 +759,7 @@ start_server {tags {"scripting"}} {
} {*attempted to create global variable 'a'*}
test {LIBRARIES - named arguments} {
- r function load LUA lib {
+ r function load {#!lua name=lib
redis.register_function{
function_name='f1',
callback=function()
@@ -761,11 +769,11 @@ start_server {tags {"scripting"}} {
}
}
r function list
- } {{library_name lib engine LUA description {} functions {{name f1 description {some desc} flags {}}}}}
+ } {{library_name lib engine LUA functions {{name f1 description {some desc} flags {}}}}}
test {LIBRARIES - named arguments, bad function name} {
catch {
- r function load LUA lib replace {
+ r function load replace {#!lua name=lib
redis.register_function{
function_name=function() return 1 end,
callback=function()
@@ -780,7 +788,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - named arguments, bad callback type} {
catch {
- r function load LUA lib replace {
+ r function load replace {#!lua name=lib
redis.register_function{
function_name='f1',
callback='bad',
@@ -793,7 +801,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - named arguments, bad description} {
catch {
- r function load LUA lib replace {
+ r function load replace {#!lua name=lib
redis.register_function{
function_name='f1',
callback=function()
@@ -808,7 +816,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - named arguments, unknown argument} {
catch {
- r function load LUA lib replace {
+ r function load replace {#!lua name=lib
redis.register_function{
function_name='f1',
callback=function()
@@ -824,7 +832,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - named arguments, missing function name} {
catch {
- r function load LUA lib replace {
+ r function load replace {#!lua name=lib
redis.register_function{
callback=function()
return 'hello'
@@ -838,7 +846,7 @@ start_server {tags {"scripting"}} {
test {LIBRARIES - named arguments, missing callback} {
catch {
- r function load LUA lib replace {
+ r function load replace {#!lua name=lib
redis.register_function{
function_name='f1',
description='desc'
@@ -850,7 +858,7 @@ start_server {tags {"scripting"}} {
test {FUNCTION - test function restore with function name collision} {
r function flush
- r function load lua lib1 {
+ r function load {#!lua name=lib1
local function add1(a)
return a + 1
end
@@ -877,7 +885,7 @@ start_server {tags {"scripting"}} {
r function flush
# load a library with different name but with the same function name
- r function load lua lib1 {
+ r function load {#!lua name=lib1
redis.register_function(
'f6',
function(keys, args)
@@ -885,7 +893,7 @@ start_server {tags {"scripting"}} {
end
)
}
- r function load lua lib2 {
+ r function load {#!lua name=lib2
local function add1(a)
return a + 1
end
@@ -926,14 +934,18 @@ start_server {tags {"scripting"}} {
test {FUNCTION - test function list with code} {
r function flush
- r function load lua library1 {redis.register_function('f6', function(keys, args) return 7 end)}
+ r function load {#!lua name=library1
+ redis.register_function('f6', function(keys, args) return 7 end)
+ }
r function list withcode
- } {{library_name library1 engine LUA description {} functions {{name f6 description {} flags {}}} library_code {redis.register_function('f6', function(keys, args) return 7 end)}}}
+ } {{library_name library1 engine LUA functions {{name f6 description {} flags {}}} library_code {*redis.register_function('f6', function(keys, args) return 7 end)*}}}
test {FUNCTION - test function list with pattern} {
- r function load lua lib1 {redis.register_function('f7', function(keys, args) return 7 end)}
+ r function load {#!lua name=lib1
+ redis.register_function('f7', function(keys, args) return 7 end)
+ }
r function list libraryname library*
- } {{library_name library1 engine LUA description {} functions {{name f6 description {} flags {}}}}}
+ } {{library_name library1 engine LUA functions {{name f6 description {} flags {}}}}}
test {FUNCTION - test function list wrong argument} {
catch {r function list bad_argument} e
@@ -957,12 +969,16 @@ start_server {tags {"scripting"}} {
test {FUNCTION - verify OOM on function load and function restore} {
r function flush
- r function load lua test replace {redis.register_function('f1', function() return 1 end)}
+ r function load replace {#!lua name=test
+ redis.register_function('f1', function() return 1 end)
+ }
set payload [r function dump]
r config set maxmemory 1
r function flush
- catch {r function load lua test replace {redis.register_function('f1', function() return 1 end)}} e
+ catch {r function load replace {#!lua name=test
+ redis.register_function('f1', function() return 1 end)
+ }} e
assert_match {*command not allowed when used memory*} $e
r function flush
@@ -973,11 +989,13 @@ start_server {tags {"scripting"}} {
}
test {FUNCTION - verify allow-omm allows running any command} {
- r FUNCTION load lua f1 replace { redis.register_function{
- function_name='f1',
- callback=function() return redis.call('set', 'x', '1') end,
- flags={'allow-oom'}
- }}
+ r FUNCTION load replace {#!lua name=f1
+ redis.register_function{
+ function_name='f1',
+ callback=function() return redis.call('set', 'x', '1') end,
+ flags={'allow-oom'}
+ }
+ }
r config set maxmemory 1
@@ -990,53 +1008,65 @@ start_server {tags {"scripting"}} {
start_server {tags {"scripting"}} {
test {FUNCTION - wrong flags type named arguments} {
- catch {r function load lua test replace {redis.register_function{
- function_name = 'f1',
- callback = function() return 1 end,
- flags = 'bad flags type'
- }}} e
+ catch {r function load replace {#!lua name=test
+ redis.register_function{
+ function_name = 'f1',
+ callback = function() return 1 end,
+ flags = 'bad flags type'
+ }
+ }} e
set _ $e
} {*flags argument to redis.register_function must be a table representing function flags*}
test {FUNCTION - wrong flag type} {
- catch {r function load lua test replace {redis.register_function{
- function_name = 'f1',
- callback = function() return 1 end,
- flags = {function() return 1 end}
- }}} e
+ catch {r function load replace {#!lua name=test
+ redis.register_function{
+ function_name = 'f1',
+ callback = function() return 1 end,
+ flags = {function() return 1 end}
+ }
+ }} e
set _ $e
} {*unknown flag given*}
test {FUNCTION - unknown flag} {
- catch {r function load lua test replace {redis.register_function{
- function_name = 'f1',
- callback = function() return 1 end,
- flags = {'unknown'}
- }}} e
+ catch {r function load replace {#!lua name=test
+ redis.register_function{
+ function_name = 'f1',
+ callback = function() return 1 end,
+ flags = {'unknown'}
+ }
+ }} e
set _ $e
} {*unknown flag given*}
test {FUNCTION - write script on fcall_ro} {
- r function load lua test replace {redis.register_function{
- function_name = 'f1',
- callback = function() return redis.call('set', 'x', 1) end
- }}
+ r function load replace {#!lua name=test
+ redis.register_function{
+ function_name = 'f1',
+ callback = function() return redis.call('set', 'x', 1) end
+ }
+ }
catch {r fcall_ro f1 0} e
set _ $e
} {*Can not execute a script with write flag using \*_ro command*}
test {FUNCTION - write script with no-writes flag} {
- r function load lua test replace {redis.register_function{
- function_name = 'f1',
- callback = function() return redis.call('set', 'x', 1) end,
- flags = {'no-writes'}
- }}
+ r function load replace {#!lua name=test
+ redis.register_function{
+ function_name = 'f1',
+ callback = function() return redis.call('set', 'x', 1) end,
+ flags = {'no-writes'}
+ }
+ }
catch {r fcall f1 0} e
set _ $e
} {*Write commands are not allowed from read-only scripts*}
test {FUNCTION - deny oom} {
- r FUNCTION load lua test replace { redis.register_function('f1', function() return redis.call('set', 'x', '1') end) }
+ r FUNCTION load replace {#!lua name=test
+ redis.register_function('f1', function() return redis.call('set', 'x', '1') end)
+ }
r config set maxmemory 1
@@ -1047,7 +1077,9 @@ start_server {tags {"scripting"}} {
}
test {FUNCTION - deny oom on no-writes function} {
- r FUNCTION load lua test replace {redis.register_function{function_name='f1', callback=function() return 'hello' end, flags={'no-writes'}}}
+ r FUNCTION load replace {#!lua name=test
+ redis.register_function{function_name='f1', callback=function() return 'hello' end, flags={'no-writes'}}
+ }
r config set maxmemory 1
@@ -1061,7 +1093,7 @@ start_server {tags {"scripting"}} {
}
test {FUNCTION - allow stale} {
- r FUNCTION load lua test replace {
+ r FUNCTION load replace {#!lua name=test
redis.register_function{function_name='f1', callback=function() return 'hello' end, flags={'no-writes'}}
redis.register_function{function_name='f2', callback=function() return 'hello' end, flags={'allow-stale', 'no-writes'}}
redis.register_function{function_name='f3', callback=function() return redis.call('get', 'x') end, flags={'allow-stale', 'no-writes'}}
@@ -1087,7 +1119,7 @@ start_server {tags {"scripting"}} {
} {} {external:skip}
test {FUNCTION - redis version api} {
- r FUNCTION load lua test replace {
+ r FUNCTION load replace {#!lua name=test
local version = redis.REDIS_VERSION_NUM
redis.register_function{function_name='get_version_v1', callback=function()
@@ -1106,12 +1138,12 @@ start_server {tags {"scripting"}} {
test {FUNCTION - function stats} {
r FUNCTION FLUSH
- r FUNCTION load lua test1 {
+ r FUNCTION load {#!lua name=test1
redis.register_function('f1', function() return 1 end)
redis.register_function('f2', function() return 1 end)
}
- r FUNCTION load lua test2 {
+ r FUNCTION load {#!lua name=test2
redis.register_function('f3', function() return 1 end)
}
@@ -1132,4 +1164,38 @@ start_server {tags {"scripting"}} {
r function flush
r function stats
} {running_script {} engines {LUA {libraries_count 0 functions_count 0}}}
+
+ test {FUNCTION - function test empty engine} {
+ catch {r function load replace {#! name=test
+ redis.register_function('foo', function() return 1 end)
+ }} e
+ set _ $e
+ } {ERR Engine '' not found}
+
+ test {FUNCTION - function test unknown metadata value} {
+ catch {r function load replace {#!lua name=test foo=bar
+ redis.register_function('foo', function() return 1 end)
+ }} e
+ set _ $e
+ } {ERR Invalid metadata value given: foo=bar}
+
+ test {FUNCTION - function test no name} {
+ catch {r function load replace {#!lua
+ redis.register_function('foo', function() return 1 end)
+ }} e
+ set _ $e
+ } {ERR Library name was not given}
+
+ test {FUNCTION - function test multiple names} {
+ catch {r function load replace {#!lua name=foo name=bar
+ redis.register_function('foo', function() return 1 end)
+ }} e
+ set _ $e
+ } {ERR Invalid metadata value, name argument was given multiple times}
+
+ test {FUNCTION - function test name with quotes} {
+ r function load replace {#!lua name="foo"
+ redis.register_function('foo', function() return 1 end)
+ }
+ } {foo}
}