MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / test_blocking_connection

Function test_blocking_connection

deps/hiredis/test.c:852–940  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

850}
851
852static void test_blocking_connection(struct config config) {
853 redisContext *c;
854 redisReply *reply;
855 int major;
856
857 c = do_connect(config);
858
859 test("Is able to deliver commands: ");
860 reply = redisCommand(c,"PING");
861 test_cond(reply->type == REDIS_REPLY_STATUS &&
862 strcasecmp(reply->str,"pong") == 0)
863 freeReplyObject(reply);
864
865 test("Is a able to send commands verbatim: ");
866 reply = redisCommand(c,"SET foo bar");
867 test_cond (reply->type == REDIS_REPLY_STATUS &&
868 strcasecmp(reply->str,"ok") == 0)
869 freeReplyObject(reply);
870
871 test("%%s String interpolation works: ");
872 reply = redisCommand(c,"SET %s %s","foo","hello world");
873 freeReplyObject(reply);
874 reply = redisCommand(c,"GET foo");
875 test_cond(reply->type == REDIS_REPLY_STRING &&
876 strcmp(reply->str,"hello world") == 0);
877 freeReplyObject(reply);
878
879 test("%%b String interpolation works: ");
880 reply = redisCommand(c,"SET %b %b","foo",(size_t)3,"hello\x00world",(size_t)11);
881 freeReplyObject(reply);
882 reply = redisCommand(c,"GET foo");
883 test_cond(reply->type == REDIS_REPLY_STRING &&
884 memcmp(reply->str,"hello\x00world",11) == 0)
885
886 test("Binary reply length is correct: ");
887 test_cond(reply->len == 11)
888 freeReplyObject(reply);
889
890 test("Can parse nil replies: ");
891 reply = redisCommand(c,"GET nokey");
892 test_cond(reply->type == REDIS_REPLY_NIL)
893 freeReplyObject(reply);
894
895 /* test 7 */
896 test("Can parse integer replies: ");
897 reply = redisCommand(c,"INCR mycounter");
898 test_cond(reply->type == REDIS_REPLY_INTEGER && reply->integer == 1)
899 freeReplyObject(reply);
900
901 test("Can parse multi bulk replies: ");
902 freeReplyObject(redisCommand(c,"LPUSH mylist foo"));
903 freeReplyObject(redisCommand(c,"LPUSH mylist bar"));
904 reply = redisCommand(c,"LRANGE mylist 0 -1");
905 test_cond(reply->type == REDIS_REPLY_ARRAY &&
906 reply->elements == 2 &&
907 !memcmp(reply->element[0]->str,"bar",3) &&
908 !memcmp(reply->element[1]->str,"foo",3))
909 freeReplyObject(reply);

Callers 1

mainFunction · 0.85

Calls 10

do_connectFunction · 0.85
freeReplyObjectFunction · 0.85
redisAppendCommandFunction · 0.85
redisGetReplyFunction · 0.85
get_redis_versionFunction · 0.85
test_resp3_push_handlerFunction · 0.85
test_resp3_push_optionsFunction · 0.85
test_privdata_hooksFunction · 0.85
disconnectFunction · 0.85
redisCommandFunction · 0.70

Tested by

no test coverage detected