summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorguybe7 <guy.benoish@redislabs.com>2022-04-25 12:05:06 +0200
committerGitHub <noreply@github.com>2022-04-25 13:05:06 +0300
commit21e39ec461cf412609475054a9755941df9365bf (patch)
tree276174009555b860f9b9abad9152fac2aff0a450 /tests
parentbd823c7fa3bce983be79835f9a306d4d7c15e31e (diff)
downloadredis-21e39ec461cf412609475054a9755941df9365bf.tar.gz
Test: RM_Call from within "expired" notification (#10613)
This case is interesting because it originates from cron, rather than from another command. The idea came from looking at #9890 and #10573, and I was wondering if RM_Call would work properly when `server.current_client == NULL`
Diffstat (limited to 'tests')
-rw-r--r--tests/modules/keyspace_events.c15
-rw-r--r--tests/unit/moduleapi/keyspace_events.tcl11
-rw-r--r--tests/unit/moduleapi/propagate.tcl6
3 files changed, 32 insertions, 0 deletions
diff --git a/tests/modules/keyspace_events.c b/tests/modules/keyspace_events.c
index 152a2c48c..58670164d 100644
--- a/tests/modules/keyspace_events.c
+++ b/tests/modules/keyspace_events.c
@@ -79,6 +79,17 @@ static int KeySpace_NotificationGeneric(RedisModuleCtx *ctx, int type, const cha
return REDISMODULE_OK;
}
+static int KeySpace_NotificationExpired(RedisModuleCtx *ctx, int type, const char *event, RedisModuleString *key) {
+ REDISMODULE_NOT_USED(type);
+ REDISMODULE_NOT_USED(event);
+ REDISMODULE_NOT_USED(key);
+
+ RedisModuleCallReply* rep = RedisModule_Call(ctx, "INCR", "c!", "testkeyspace:expired");
+ RedisModule_FreeCallReply(rep);
+
+ return REDISMODULE_OK;
+}
+
static int KeySpace_NotificationModule(RedisModuleCtx *ctx, int type, const char *event, RedisModuleString *key) {
REDISMODULE_NOT_USED(ctx);
REDISMODULE_NOT_USED(type);
@@ -233,6 +244,10 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
return REDISMODULE_ERR;
}
+ if(RedisModule_SubscribeToKeyspaceEvents(ctx, REDISMODULE_NOTIFY_EXPIRED, KeySpace_NotificationExpired) != REDISMODULE_OK){
+ return REDISMODULE_ERR;
+ }
+
if(RedisModule_SubscribeToKeyspaceEvents(ctx, REDISMODULE_NOTIFY_MODULE, KeySpace_NotificationModule) != REDISMODULE_OK){
return REDISMODULE_ERR;
}
diff --git a/tests/unit/moduleapi/keyspace_events.tcl b/tests/unit/moduleapi/keyspace_events.tcl
index 39350e518..ceec6fdf3 100644
--- a/tests/unit/moduleapi/keyspace_events.tcl
+++ b/tests/unit/moduleapi/keyspace_events.tcl
@@ -83,6 +83,17 @@ tags "modules" {
$rd1 close
}
+ test {Test expired key space event} {
+ set prev_expired [s expired_keys]
+ r set exp 1 PX 10
+ wait_for_condition 100 10 {
+ [s expired_keys] eq $prev_expired + 1
+ } else {
+ fail "key not expired"
+ }
+ assert_equal [r get testkeyspace:expired] 1
+ }
+
test "Unload the module - testkeyspace" {
assert_equal {OK} [r module unload testkeyspace]
}
diff --git a/tests/unit/moduleapi/propagate.tcl b/tests/unit/moduleapi/propagate.tcl
index bbc9d3800..846d938fb 100644
--- a/tests/unit/moduleapi/propagate.tcl
+++ b/tests/unit/moduleapi/propagate.tcl
@@ -108,10 +108,16 @@ tags "modules" {
{set asdf3 3 PXAT *}
{exec}
{incr notifications}
+ {incr notifications}
+ {incr testkeyspace:expired}
{del asdf*}
{incr notifications}
+ {incr notifications}
+ {incr testkeyspace:expired}
{del asdf*}
{incr notifications}
+ {incr notifications}
+ {incr testkeyspace:expired}
{del asdf*}
}
close_replication_stream $repl