Unverified Commit 6a9cc20d authored by Valentino Geron's avatar Valentino Geron Committed by GitHub
Browse files

Tests: Add missing key declaration in scripts (#11134)



Make sure the script calls in the tests declare the keys they intend to use.
Do that with minimal changes to existing lines (so many scripts still have a hard coded key names)
Co-authored-by: default avatarValentino Geron <valentino@redis.com>
parent ac1cc5a6
...@@ -209,14 +209,14 @@ start_server {tags {"scripting"}} { ...@@ -209,14 +209,14 @@ start_server {tags {"scripting"}} {
test {FUNCTION - test fcall_ro with write command} { 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 redis.call('set', 'x', '1')}]
catch { r fcall_ro test 0 } e catch { r fcall_ro test 1 x } e
set _ $e set _ $e
} {*Write commands are not allowed from read-only scripts*} } {*Write commands are not allowed from read-only scripts*}
test {FUNCTION - test fcall_ro with read only commands} { 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 redis.call('get', 'x')}]
r set x 1 r set x 1
r fcall_ro test 0 r fcall_ro test 1 x
} {1} } {1}
test {FUNCTION - test keys and argv} { test {FUNCTION - test keys and argv} {
...@@ -410,7 +410,7 @@ start_server {tags {"scripting repl external:skip"}} { ...@@ -410,7 +410,7 @@ start_server {tags {"scripting repl external:skip"}} {
test "FUNCTION - function effect is replicated to 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 redis.call('set', 'x', '1')}]
r fcall test 0 r fcall test 1 x
assert {[r get x] eq {1}} assert {[r get x] eq {1}}
wait_for_condition 150 100 { wait_for_condition 150 100 {
[r -1 get x] eq {1} [r -1 get x] eq {1}
...@@ -421,7 +421,7 @@ start_server {tags {"scripting repl external:skip"}} { ...@@ -421,7 +421,7 @@ start_server {tags {"scripting repl external:skip"}} {
test "FUNCTION - modify key space of read only replica" { test "FUNCTION - modify key space of read only replica" {
catch { catch {
r -1 fcall test 0 r -1 fcall test 1 x
} e } e
set _ $e set _ $e
} {READONLY You can't write against a read only replica.} } {READONLY You can't write against a read only replica.}
...@@ -1037,7 +1037,7 @@ start_server {tags {"scripting"}} { ...@@ -1037,7 +1037,7 @@ start_server {tags {"scripting"}} {
callback = function() return redis.call('set', 'x', 1) end callback = function() return redis.call('set', 'x', 1) end
} }
} }
catch {r fcall_ro f1 0} e catch {r fcall_ro f1 1 x} e
set _ $e set _ $e
} {*Can not execute a script with write flag using \*_ro command*} } {*Can not execute a script with write flag using \*_ro command*}
...@@ -1049,7 +1049,7 @@ start_server {tags {"scripting"}} { ...@@ -1049,7 +1049,7 @@ start_server {tags {"scripting"}} {
flags = {'no-writes'} flags = {'no-writes'}
} }
} }
catch {r fcall f1 0} e catch {r fcall f1 1 x} e
set _ $e set _ $e
} {*Write commands are not allowed from read-only scripts*} } {*Write commands are not allowed from read-only scripts*}
...@@ -1060,7 +1060,7 @@ start_server {tags {"scripting"}} { ...@@ -1060,7 +1060,7 @@ start_server {tags {"scripting"}} {
r config set maxmemory 1 r config set maxmemory 1
catch {[r fcall f1 1 k]} e catch {[r fcall f1 1 x]} e
assert_match {OOM *when used memory > 'maxmemory'*} $e assert_match {OOM *when used memory > 'maxmemory'*} $e
r config set maxmemory 0 r config set maxmemory 0
...@@ -1095,7 +1095,7 @@ start_server {tags {"scripting"}} { ...@@ -1095,7 +1095,7 @@ start_server {tags {"scripting"}} {
assert_equal {hello} [r fcall f2 0] assert_equal {hello} [r fcall f2 0]
catch {[r fcall f3 0]} e catch {[r fcall f3 1 x]} e
assert_match {ERR *Can not execute the command on a stale replica*} $e assert_match {ERR *Can not execute the command on a stale replica*} $e
assert_match {*redis_version*} [r fcall f4 0] assert_match {*redis_version*} [r fcall f4 0]
......
...@@ -68,7 +68,7 @@ start_server {tags {"scripting"}} { ...@@ -68,7 +68,7 @@ start_server {tags {"scripting"}} {
} {} } {}
test {EVAL - Return table with a metatable that call redis} { test {EVAL - Return table with a metatable that call redis} {
run_script {local a = {}; setmetatable(a,{__index=function() redis.call('set', 'x', '1') end}) return a} 0 run_script {local a = {}; setmetatable(a,{__index=function() redis.call('set', 'x', '1') end}) return a} 1 x
# make sure x was not set # make sure x was not set
r get x r get x
} {} } {}
...@@ -215,37 +215,37 @@ start_server {tags {"scripting"}} { ...@@ -215,37 +215,37 @@ start_server {tags {"scripting"}} {
test {EVAL - Scripts can't run blpop command} { test {EVAL - Scripts can't run blpop command} {
set e {} set e {}
catch {run_script {return redis.pcall('blpop','x',0)} 0} e catch {run_script {return redis.pcall('blpop','x',0)} 1 x} e
set e set e
} {*not allowed*} } {*not allowed*}
test {EVAL - Scripts can't run brpop command} { test {EVAL - Scripts can't run brpop command} {
set e {} set e {}
catch {run_script {return redis.pcall('brpop','empty_list',0)} 0} e catch {run_script {return redis.pcall('brpop','empty_list',0)} 1 empty_list} e
set e set e
} {*not allowed*} } {*not allowed*}
test {EVAL - Scripts can't run brpoplpush command} { test {EVAL - Scripts can't run brpoplpush command} {
set e {} set e {}
catch {run_script {return redis.pcall('brpoplpush','empty_list1', 'empty_list2',0)} 0} e catch {run_script {return redis.pcall('brpoplpush','empty_list1{t}', 'empty_list2{t}',0)} 2 empty_list1{t} empty_list2{t}} e
set e set e
} {*not allowed*} } {*not allowed*}
test {EVAL - Scripts can't run blmove command} { test {EVAL - Scripts can't run blmove command} {
set e {} set e {}
catch {run_script {return redis.pcall('blmove','empty_list1', 'empty_list2', 'LEFT', 'LEFT', 0)} 0} e catch {run_script {return redis.pcall('blmove','empty_list1{t}', 'empty_list2{t}', 'LEFT', 'LEFT', 0)} 2 empty_list1{t} empty_list2{t}} e
set e set e
} {*not allowed*} } {*not allowed*}
test {EVAL - Scripts can't run bzpopmin command} { test {EVAL - Scripts can't run bzpopmin command} {
set e {} set e {}
catch {run_script {return redis.pcall('bzpopmin','empty_zset', 0)} 0} e catch {run_script {return redis.pcall('bzpopmin','empty_zset', 0)} 1 empty_zset} e
set e set e
} {*not allowed*} } {*not allowed*}
test {EVAL - Scripts can't run bzpopmax command} { test {EVAL - Scripts can't run bzpopmax command} {
set e {} set e {}
catch {run_script {return redis.pcall('bzpopmax','empty_zset', 0)} 0} e catch {run_script {return redis.pcall('bzpopmax','empty_zset', 0)} 1 empty_zset} e
set e set e
} {*not allowed*} } {*not allowed*}
...@@ -263,7 +263,7 @@ start_server {tags {"scripting"}} { ...@@ -263,7 +263,7 @@ start_server {tags {"scripting"}} {
test {EVAL - Scripts can run non-deterministic commands} { test {EVAL - Scripts can run non-deterministic commands} {
set e {} set e {}
catch { catch {
run_script "redis.pcall('randomkey'); return redis.pcall('set','x','ciao')" 0 run_script {redis.pcall('randomkey'); return redis.pcall('set','x','ciao')} 1 x
} e } e
set e set e
} {*OK*} } {*OK*}
...@@ -702,7 +702,7 @@ start_server {tags {"scripting"}} { ...@@ -702,7 +702,7 @@ start_server {tags {"scripting"}} {
a[i] = 1 a[i] = 1
end end
return redis.call("lpush", "l", unpack(a)) return redis.call("lpush", "l", unpack(a))
} 0 } 1 l
} {7999} } {7999}
test "Script read key with expiration set" { test "Script read key with expiration set" {
...@@ -713,7 +713,7 @@ start_server {tags {"scripting"}} { ...@@ -713,7 +713,7 @@ start_server {tags {"scripting"}} {
else else
return redis.call("EXISTS", "key") return redis.call("EXISTS", "key")
end end
} 0] "value" } 1 key] "value"
} }
test "Script del key with expiration set" { test "Script del key with expiration set" {
...@@ -721,7 +721,7 @@ start_server {tags {"scripting"}} { ...@@ -721,7 +721,7 @@ start_server {tags {"scripting"}} {
assert_equal [run_script { assert_equal [run_script {
redis.call("DEL", "key") redis.call("DEL", "key")
return redis.call("EXISTS", "key") return redis.call("EXISTS", "key")
} 0] 0 } 1 key] 0
} }
test "Script ACL check" { test "Script ACL check" {
...@@ -1061,14 +1061,14 @@ start_server {tags {"scripting"}} { ...@@ -1061,14 +1061,14 @@ start_server {tags {"scripting"}} {
redis.call("incr","x") redis.call("incr","x")
redis.call("select","11") redis.call("select","11")
redis.call("incr","z") redis.call("incr","z")
} 0 } 3 foo1 x z
run_script { run_script {
redis.call("set","foo1","bar1") redis.call("set","foo1","bar1")
redis.call("select","10") redis.call("select","10")
redis.call("incr","x") redis.call("incr","x")
redis.call("select","11") redis.call("select","11")
redis.call("incr","z") redis.call("incr","z")
} 0 } 3 foo1 x z
wait_for_condition 50 100 { wait_for_condition 50 100 {
[debug_digest -1] eq [debug_digest] [debug_digest -1] eq [debug_digest]
} else { } else {
...@@ -1126,7 +1126,7 @@ start_server {tags {"scripting repl external:skip"}} { ...@@ -1126,7 +1126,7 @@ start_server {tags {"scripting repl external:skip"}} {
redis.call('set','c','3'); redis.call('set','c','3');
redis.set_repl(redis.REPL_ALL); redis.set_repl(redis.REPL_ALL);
redis.call('set','d','4'); redis.call('set','d','4');
} 0 } 4 a b c d
wait_for_condition 50 100 { wait_for_condition 50 100 {
[r -1 mget a b c d] eq {1 {} {} 4} [r -1 mget a b c d] eq {1 {} {} 4}
...@@ -1358,7 +1358,7 @@ start_server {tags {"scripting needs:debug"}} { ...@@ -1358,7 +1358,7 @@ start_server {tags {"scripting needs:debug"}} {
redis.call("SET", "key", "value", "PX", "1") redis.call("SET", "key", "value", "PX", "1")
redis.call("DEBUG", "SLEEP", 0.01) redis.call("DEBUG", "SLEEP", 0.01)
return redis.call("EXISTS", "key") return redis.call("EXISTS", "key")
} 0] 1 } 1 key] 1
assert_equal 0 [r EXISTS key] assert_equal 0 [r EXISTS key]
} }
...@@ -1371,7 +1371,7 @@ start_server {tags {"scripting needs:debug"}} { ...@@ -1371,7 +1371,7 @@ start_server {tags {"scripting needs:debug"}} {
# use DEBUG OBJECT to make sure it doesn't error (means the key still exists) # use DEBUG OBJECT to make sure it doesn't error (means the key still exists)
r DEBUG OBJECT key r DEBUG OBJECT key
assert_equal [run_script "return redis.call('EXISTS', 'key')" 0] 0 assert_equal [run_script {return redis.call('EXISTS', 'key')} 1 key] 0
assert_equal 0 [r EXISTS key] assert_equal 0 [r EXISTS key]
r DEBUG set-active-expire 1 r DEBUG set-active-expire 1
} }
......
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