diff options
author | Meir Shpilraien (Spielrein) <meir@redis.com> | 2021-12-16 17:58:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-16 17:58:25 +0200 |
commit | 687210f1550cf9048bed5f5539c9411fb22cd3b0 (patch) | |
tree | 6bd085128bbc5203edb46c61c41f0d74c0967b5d /tests | |
parent | ffbe36fc3ee824407b3818c0a6f861176ce56482 (diff) | |
download | redis-687210f1550cf9048bed5f5539c9411fb22cd3b0.tar.gz |
Add FUNCTION FLUSH command to flush all functions (#9936)
Added `FUNCTION FLUSH` command. The new sub-command allows delete all the functions.
An optional `[SYNC|ASYNC]` argument can be given to control whether or not to flush the
functions synchronously or asynchronously. if not given the default flush mode is chosen by
`lazyfree-lazy-user-flush` configuration values.
Add the missing `functions.tcl` test to the list of tests that are executed in test_helper.tcl,
and call FUNCTION FLUSH in between servers in external mode
Diffstat (limited to 'tests')
-rw-r--r-- | tests/support/server.tcl | 1 | ||||
-rw-r--r-- | tests/test_helper.tcl | 1 | ||||
-rw-r--r-- | tests/unit/functions.tcl | 42 |
3 files changed, 43 insertions, 1 deletions
diff --git a/tests/support/server.tcl b/tests/support/server.tcl index 4c63d7b3a..ee39c8df9 100644 --- a/tests/support/server.tcl +++ b/tests/support/server.tcl @@ -343,6 +343,7 @@ proc run_external_server_test {code overrides} { } r flushall + r function flush # store overrides set saved_config {} diff --git a/tests/test_helper.tcl b/tests/test_helper.tcl index d1405e3e3..570d9e85f 100644 --- a/tests/test_helper.tcl +++ b/tests/test_helper.tcl @@ -63,6 +63,7 @@ set ::all_tests { unit/pubsub unit/slowlog unit/scripting + unit/functions unit/maxmemory unit/introspection unit/introspection-2 diff --git a/tests/unit/functions.tcl b/tests/unit/functions.tcl index 0736a44da..27bb29b72 100644 --- a/tests/unit/functions.tcl +++ b/tests/unit/functions.tcl @@ -185,9 +185,34 @@ start_server {tags {"scripting"}} { after 200 ; # Give some time to Lua to call the hook again... assert_equal [r ping] "PONG" } + + test {FUNCTION - test function flush} { + r function create lua test REPLACE {local a = 1 while true do a = a + 1 end} + assert_match {{name test engine LUA description {}}} [r function list] + r function flush + assert_match {} [r function list] + + r function create lua test REPLACE {local a = 1 while true do a = a + 1 end} + assert_match {{name test engine LUA description {}}} [r function list] + r function flush async + assert_match {} [r function list] + + r function create lua test REPLACE {local a = 1 while true do a = a + 1 end} + assert_match {{name test engine LUA description {}}} [r function list] + r function flush sync + assert_match {} [r function list] + } + + test {FUNCTION - test function wrong argument} { + catch {r function flush bad_arg} e + assert_match {*only supports SYNC|ASYNC*} $e + + catch {r function flush sync extra_arg} e + assert_match {*wrong number of arguments*} $e + } } -start_server {tags {"scripting repl"}} { +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] @@ -221,6 +246,21 @@ start_server {tags {"scripting repl"}} { } } + test {FUNCTION - flush is replicated to replica} { + r function create LUA test DESCRIPTION {some description} {return 'hello'} + wait_for_condition 50 100 { + [r -1 function list] eq {{name test engine LUA description {some description}}} + } else { + fail "Failed waiting for function to replicate to replica" + } + r function flush + wait_for_condition 50 100 { + [r -1 function list] eq {} + } else { + fail "Failed waiting for function to replicate to replica" + } + } + test "Disconnecting the replica from master instance" { r -1 slaveof no one # creating a function after disconnect to make sure function |