diff --git a/src/eval.c b/src/eval.c index 30e0a80b39..e34791ffb6 100644 --- a/src/eval.c +++ b/src/eval.c @@ -142,8 +142,10 @@ void freeEvalScripts(dict *scripts, list *scripts_lru_list, list *engine_callbac listNode *node = NULL; while ((node = listNext(iter)) != NULL) { callableLazyEvalReset *callback = listNodeValue(node); - callback->engineLazyEvalResetCallback(callback->context); - zfree(callback); + if (callback != NULL) { + callback->engineLazyEvalResetCallback(callback->context); + zfree(callback); + } } listReleaseIterator(iter); listRelease(engine_callbacks); diff --git a/src/valkeymodule.h b/src/valkeymodule.h index 84eaaff6f8..50516616c2 100644 --- a/src/valkeymodule.h +++ b/src/valkeymodule.h @@ -847,7 +847,7 @@ typedef struct ValkeyModuleScriptingEngineCallableLazyEvalReset { /* * Callback function used for resetting the EVAL context implemented by an - * an engine. This callback will be called by a background thread when it's + * engine. This callback will be called by a background thread when it's * ready for resetting the context. * * - `context`: a generic pointer to a context object, stored in the diff --git a/tests/modules/helloscripting.c b/tests/modules/helloscripting.c index f0960b4a96..b39b703820 100644 --- a/tests/modules/helloscripting.c +++ b/tests/modules/helloscripting.c @@ -430,6 +430,15 @@ callHelloLangFunction(ValkeyModuleCtx *module_ctx, ValkeyModule_ReplyWithLongLong(module_ctx, result); } +static ValkeyModuleScriptingEngineCallableLazyEvalReset *helloResetEvalEnv(ValkeyModuleCtx *module_ctx, + ValkeyModuleScriptingEngineCtx *engine_ctx, + int async) { + VALKEYMODULE_NOT_USED(module_ctx); + VALKEYMODULE_NOT_USED(engine_ctx); + VALKEYMODULE_NOT_USED(async); + return NULL; +} + int ValkeyModule_OnLoad(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) { @@ -449,7 +458,7 @@ int ValkeyModule_OnLoad(ValkeyModuleCtx *ctx, .free_function = engineFreeFunction, .call_function = callHelloLangFunction, .get_function_memory_overhead = engineFunctionMemoryOverhead, - .reset_eval_env = NULL, + .reset_eval_env = helloResetEvalEnv, .get_memory_info = engineGetMemoryInfo, }; diff --git a/tests/unit/moduleapi/scriptingengine.tcl b/tests/unit/moduleapi/scriptingengine.tcl index 78f6572904..a626164aa9 100644 --- a/tests/unit/moduleapi/scriptingengine.tcl +++ b/tests/unit/moduleapi/scriptingengine.tcl @@ -126,12 +126,12 @@ start_server {tags {"modules"}} { test {Test function kill} { set rd [valkey_deferring_client] r config set busy-reply-threshold 10 - r function load REPLACE "#!hello name=mylib\nFUNCTION sleep\nARGS 0\nSLEEP\nARGS 0\nRETURN" - $rd fcall sleep 0 100 + r function load REPLACE "#!hello name=mylib\nFUNCTION wait\nARGS 0\nSLEEP\nARGS 0\nRETURN" + $rd fcall wait 0 100 after 1000 catch {r ping} e assert_match {BUSY*} $e - assert_match {running_script {name sleep command {fcall sleep 0 100} duration_ms *} engines {*}} [r FUNCTION STATS] + assert_match {running_script {name wait command {fcall wait 0 100} duration_ms *} engines {*}} [r FUNCTION STATS] r function kill after 1000 ; assert_equal [r ping] "PONG" @@ -139,6 +139,41 @@ start_server {tags {"modules"}} { $rd close } + test {Test eval execution} { + set result [r eval "#!hello\nFUNCTION foo\nARGS 0\nRETURN" 0 145] + assert_equal $result 145 + } + + test {Test evalsha execution} { + set sha [r script load "#!hello\nFUNCTION foo\nARGS 0\nRETURN"] + set result [r evalsha $sha 0 167] + assert_equal $result 167 + } + + test {Test script exists} { + set sha [r script load "#!hello\nFUNCTION foo\nARGS 0\nRETURN"] + set result [r script exists $sha] + assert_equal $result 1 + } + + test {Test script flush sync} { + set sha [r script load "#!hello\nFUNCTION foo\nARGS 0\nRETURN"] + set result [r script exists $sha] + assert_equal $result 1 + r script flush SYNC + set result [r script exists $sha] + assert_equal $result 0 + } + + test {Test script flush async} { + set sha [r script load "#!hello\nFUNCTION foo\nARGS 0\nRETURN"] + set result [r script exists $sha] + assert_equal $result 1 + r script flush ASYNC + set result [r script exists $sha] + assert_equal $result 0 + } + test {Unload scripting engine module} { set result [r module unload helloengine] assert_equal $result "OK"