summaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
authorBjorn Svensson <bjorn.a.svensson@est.tech>2021-12-22 19:44:29 +0100
committerGitHub <noreply@github.com>2021-12-22 10:44:29 -0800
commit58aacdac65a04f611e2a659cd60ffa283b8bdf54 (patch)
tree40e2e95128f4952b1e511fcb7b2324a2532c05c1 /test.c
parentd3384260e7e1726747bd78474e4b0874a4b0a236 (diff)
Handle array response in parallell with pubsub using RESP3 (#1014)
RESP3 allows sending commands in parallell with pubsub handling and these commands might get responded with a REDIS_REPLY_ARRAY. This conflicts with the pubsub response handling for RESP2 and results in a faulty state when using RESP3. Add functionality to keep track of PUSH/RESP3 support on the connection and only expect the message type REDIS_REPLY_PUSH as subscribe messages when once seen.
Diffstat (limited to 'test.c')
-rw-r--r--test.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/test.c b/test.c
index ec1c419..6915ba2 100644
--- a/test.c
+++ b/test.c
@@ -1567,6 +1567,15 @@ void unexpected_push_cb(redisAsyncContext *ac, void *r) {
exit(1);
}
+/* Expect a reply of type INTEGER */
+void integer_cb(redisAsyncContext *ac, void *r, void *privdata) {
+ (void) ac;
+ redisReply *reply = r;
+ TestState *state = privdata;
+ assert(reply != NULL && reply->type == REDIS_REPLY_INTEGER);
+ state->checkpoint++;
+}
+
static void test_pubsub_handling_resp3(struct config config) {
test("Subscribe, handle published message and unsubscribe using RESP3: ");
/* Setup event dispatcher with a testcase timeout */
@@ -1594,13 +1603,20 @@ static void test_pubsub_handling_resp3(struct config config) {
TestState state = {.options = &options, .resp3 = 1};
redisAsyncCommand(ac,subscribe_cb,&state,"subscribe mychannel");
+ /* Make sure non-subscribe commands are handled in RESP3 */
+ redisAsyncCommand(ac,integer_cb,&state,"LPUSH mylist foo");
+ redisAsyncCommand(ac,integer_cb,&state,"LPUSH mylist foo");
+ redisAsyncCommand(ac,integer_cb,&state,"LPUSH mylist foo");
+ /* Handle an array with 3 elements as a non-subscribe command */
+ redisAsyncCommand(ac,array_cb,&state,"LRANGE mylist 0 2");
+
/* Start event dispatching loop */
test_cond(event_base_dispatch(base) == 0);
event_free(timeout);
event_base_free(base);
/* Verify test checkpoints */
- assert(state.checkpoint == 1);
+ assert(state.checkpoint == 5);
}
#endif