MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_resp3_push_handler

Function test_resp3_push_handler

app/redis-6.2.6/deps/hiredis/test.c:726–784  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

724}
725
726static void test_resp3_push_handler(redisContext *c) {
727 struct pushCounters pc = {0};
728 redisPushFn *old = NULL;
729 redisReply *reply;
730 void *privdata;
731
732 /* Switch to RESP3 and turn on client tracking */
733 send_hello(c, 3);
734 send_client_tracking(c, "ON");
735 privdata = c->privdata;
736 c->privdata = &pc;
737
738 reply = redisCommand(c, "GET key:0");
739 assert(reply != NULL);
740 freeReplyObject(reply);
741
742 test("RESP3 PUSH messages are handled out of band by default: ");
743 reply = redisCommand(c, "SET key:0 val:0");
744 test_cond(reply != NULL && reply->type == REDIS_REPLY_STATUS);
745 freeReplyObject(reply);
746
747 assert((reply = redisCommand(c, "GET key:0")) != NULL);
748 freeReplyObject(reply);
749
750 old = redisSetPushCallback(c, push_handler);
751 test("We can set a custom RESP3 PUSH handler: ");
752 reply = redisCommand(c, "SET key:0 val:0");
753 test_cond(reply != NULL && reply->type == REDIS_REPLY_STATUS && pc.str == 1);
754 freeReplyObject(reply);
755
756 test("We properly handle a NIL invalidation payload: ");
757 reply = redisCommand(c, "FLUSHDB");
758 test_cond(reply != NULL && reply->type == REDIS_REPLY_STATUS && pc.nil == 1);
759 freeReplyObject(reply);
760
761 /* Unset the push callback and generate an invalidate message making
762 * sure it is not handled out of band. */
763 test("With no handler, PUSH replies come in-band: ");
764 redisSetPushCallback(c, NULL);
765 assert((reply = redisCommand(c, "GET key:0")) != NULL);
766 freeReplyObject(reply);
767 assert((reply = redisCommand(c, "SET key:0 invalid")) != NULL);
768 test_cond(reply->type == REDIS_REPLY_PUSH);
769 freeReplyObject(reply);
770
771 test("With no PUSH handler, no replies are lost: ");
772 assert(redisGetReply(c, (void**)&reply) == REDIS_OK);
773 test_cond(reply != NULL && reply->type == REDIS_REPLY_STATUS);
774 freeReplyObject(reply);
775
776 /* Return to the originally set PUSH handler */
777 assert(old != NULL);
778 redisSetPushCallback(c, old);
779
780 /* Switch back to RESP2 and disable tracking */
781 c->privdata = privdata;
782 send_client_tracking(c, "OFF");
783 send_hello(c, 2);

Callers 1

test_blocking_connectionFunction · 0.85

Calls 7

send_helloFunction · 0.85
send_client_trackingFunction · 0.85
freeReplyObjectFunction · 0.85
redisSetPushCallbackFunction · 0.85
redisGetReplyFunction · 0.85
redisCommandFunction · 0.70
testClass · 0.50

Tested by

no test coverage detected