summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2019-10-03 18:44:47 +0200
committerantirez <antirez@gmail.com>2019-10-03 18:44:50 +0200
commit1b8b8c029fa09511bfeb01c1808456de7a28565d (patch)
tree7ca4be08a05c9f1f09098144000507824268a772
parent55a3da87f83c7c912b6c981a3e9fb1259179007a (diff)
downloadredis-1b8b8c029fa09511bfeb01c1808456de7a28565d.tar.gz
Modules: add RM_Replicate() Tcl test file & fix the module.
-rwxr-xr-xruntest-moduleapi2
-rw-r--r--tests/modules/propagate.c1
-rw-r--r--tests/unit/moduleapi/propagate.tcl30
3 files changed, 32 insertions, 1 deletions
diff --git a/runtest-moduleapi b/runtest-moduleapi
index 1f090ff65..a16cca686 100755
--- a/runtest-moduleapi
+++ b/runtest-moduleapi
@@ -13,4 +13,4 @@ then
fi
make -C tests/modules && \
-$TCLSH tests/test_helper.tcl --single unit/moduleapi/commandfilter --single unit/moduleapi/fork --single unit/moduleapi/testrdb --single unit/moduleapi/infotest "${@}"
+$TCLSH tests/test_helper.tcl --single unit/moduleapi/commandfilter --single unit/moduleapi/fork --single unit/moduleapi/testrdb --single unit/moduleapi/infotest --single unit/moduleapi/propagate "${@}"
diff --git a/tests/modules/propagate.c b/tests/modules/propagate.c
index fbd3ec359..f83af1799 100644
--- a/tests/modules/propagate.c
+++ b/tests/modules/propagate.c
@@ -61,6 +61,7 @@ void timerHandler(RedisModuleCtx *ctx, void *data) {
void *threadMain(void *arg) {
REDISMODULE_NOT_USED(arg);
RedisModuleCtx *ctx = RedisModule_GetThreadSafeContext(NULL);
+ RedisModule_SelectDb(ctx,9); /* Tests ran in database number 9. */
for (int i = 0; i < 10; i++) {
RedisModule_ThreadSafeContextLock(ctx);
RedisModule_Replicate(ctx,"INCR","c","thread");
diff --git a/tests/unit/moduleapi/propagate.tcl b/tests/unit/moduleapi/propagate.tcl
new file mode 100644
index 000000000..71307ce33
--- /dev/null
+++ b/tests/unit/moduleapi/propagate.tcl
@@ -0,0 +1,30 @@
+set testmodule [file normalize tests/modules/propagate.so]
+
+tags "modules" {
+ test {Modules can propagate in async and threaded contexts} {
+ start_server {} {
+ set replica [srv 0 client]
+ set replica_host [srv 0 host]
+ set replica_port [srv 0 port]
+ start_server [list overrides [list loadmodule "$testmodule"]] {
+ set master [srv 0 client]
+ set master_host [srv 0 host]
+ set master_port [srv 0 port]
+
+ # Start the replication process...
+ $replica replicaof $master_host $master_port
+ wait_for_sync $replica
+
+ after 1000
+ $master propagate-test
+
+ wait_for_condition 5000 10 {
+ ([$replica get timer] eq "10") && \
+ ([$replica get thread] eq "10")
+ } else {
+ fail "The two counters don't match the expected value."
+ }
+ }
+ }
+ }
+}