diff options
Diffstat (limited to 'test.c')
-rw-r--r-- | test.c | 198 |
1 files changed, 99 insertions, 99 deletions
@@ -236,110 +236,110 @@ static void cleanup() { redisFree(c); } -static long __test_callback_flags = 0; -static void __test_callback(redisContext *c, void *privdata) { - ((void)c); - /* Shift to detect execution order */ - __test_callback_flags <<= 8; - __test_callback_flags |= (long)privdata; -} - -static void __test_reply_callback(redisContext *c, redisReply *reply, void *privdata) { - ((void)c); - /* Shift to detect execution order */ - __test_callback_flags <<= 8; - __test_callback_flags |= (long)privdata; - if (reply) freeReplyObject(reply); -} - -static redisContext *__connect_nonblock() { - /* Reset callback flags */ - __test_callback_flags = 0; - return redisConnectNonBlock("127.0.0.1", 6379, NULL); -} - -static void test_nonblocking_connection() { - redisContext *c; - int wdone = 0; - - test("Calls command callback when command is issued: "); - c = __connect_nonblock(); - redisSetCommandCallback(c,__test_callback,(void*)1); - redisCommand(c,"PING"); - test_cond(__test_callback_flags == 1); - redisFree(c); - - test("Calls disconnect callback on redisDisconnect: "); - c = __connect_nonblock(); - redisSetDisconnectCallback(c,__test_callback,(void*)2); - redisDisconnect(c); - test_cond(__test_callback_flags == 2); - redisFree(c); - - test("Calls disconnect callback and free callback on redisFree: "); - c = __connect_nonblock(); - redisSetDisconnectCallback(c,__test_callback,(void*)2); - redisSetFreeCallback(c,__test_callback,(void*)4); - redisFree(c); - test_cond(__test_callback_flags == ((2 << 8) | 4)); - - test("redisBufferWrite against empty write buffer: "); - c = __connect_nonblock(); - test_cond(redisBufferWrite(c,&wdone) == REDIS_OK && wdone == 1); - redisFree(c); - - test("redisBufferWrite against not yet connected fd: "); - c = __connect_nonblock(); - redisCommand(c,"PING"); - test_cond(redisBufferWrite(c,NULL) == REDIS_ERR && - strncmp(c->error,"write:",6) == 0); - redisFree(c); - - test("redisBufferWrite against closed fd: "); - c = __connect_nonblock(); - redisCommand(c,"PING"); - redisDisconnect(c); - test_cond(redisBufferWrite(c,NULL) == REDIS_ERR && - strncmp(c->error,"write:",6) == 0); - redisFree(c); - - test("Process callbacks in the right sequence: "); - c = __connect_nonblock(); - redisCommandWithCallback(c,__test_reply_callback,(void*)1,"PING"); - redisCommandWithCallback(c,__test_reply_callback,(void*)2,"PING"); - redisCommandWithCallback(c,__test_reply_callback,(void*)3,"PING"); - - /* Write output buffer */ - wdone = 0; - while(!wdone) { - usleep(500); - redisBufferWrite(c,&wdone); - } - - /* Read until at least one callback is executed (the 3 replies will - * arrive in a single packet, causing all callbacks to be executed in - * a single pass). */ - while(__test_callback_flags == 0) { - assert(redisBufferRead(c) == REDIS_OK); - redisProcessCallbacks(c); - } - test_cond(__test_callback_flags == 0x010203); - redisFree(c); - - test("redisDisconnect executes pending callbacks with NULL reply: "); - c = __connect_nonblock(); - redisSetDisconnectCallback(c,__test_callback,(void*)1); - redisCommandWithCallback(c,__test_reply_callback,(void*)2,"PING"); - redisDisconnect(c); - test_cond(__test_callback_flags == 0x0201); - redisFree(c); -} +// static long __test_callback_flags = 0; +// static void __test_callback(redisContext *c, void *privdata) { +// ((void)c); +// /* Shift to detect execution order */ +// __test_callback_flags <<= 8; +// __test_callback_flags |= (long)privdata; +// } +// +// static void __test_reply_callback(redisContext *c, redisReply *reply, void *privdata) { +// ((void)c); +// /* Shift to detect execution order */ +// __test_callback_flags <<= 8; +// __test_callback_flags |= (long)privdata; +// if (reply) freeReplyObject(reply); +// } +// +// static redisContext *__connect_nonblock() { +// /* Reset callback flags */ +// __test_callback_flags = 0; +// return redisConnectNonBlock("127.0.0.1", 6379, NULL); +// } +// +// static void test_nonblocking_connection() { +// redisContext *c; +// int wdone = 0; +// +// test("Calls command callback when command is issued: "); +// c = __connect_nonblock(); +// redisSetCommandCallback(c,__test_callback,(void*)1); +// redisCommand(c,"PING"); +// test_cond(__test_callback_flags == 1); +// redisFree(c); +// +// test("Calls disconnect callback on redisDisconnect: "); +// c = __connect_nonblock(); +// redisSetDisconnectCallback(c,__test_callback,(void*)2); +// redisDisconnect(c); +// test_cond(__test_callback_flags == 2); +// redisFree(c); +// +// test("Calls disconnect callback and free callback on redisFree: "); +// c = __connect_nonblock(); +// redisSetDisconnectCallback(c,__test_callback,(void*)2); +// redisSetFreeCallback(c,__test_callback,(void*)4); +// redisFree(c); +// test_cond(__test_callback_flags == ((2 << 8) | 4)); +// +// test("redisBufferWrite against empty write buffer: "); +// c = __connect_nonblock(); +// test_cond(redisBufferWrite(c,&wdone) == REDIS_OK && wdone == 1); +// redisFree(c); +// +// test("redisBufferWrite against not yet connected fd: "); +// c = __connect_nonblock(); +// redisCommand(c,"PING"); +// test_cond(redisBufferWrite(c,NULL) == REDIS_ERR && +// strncmp(c->error,"write:",6) == 0); +// redisFree(c); +// +// test("redisBufferWrite against closed fd: "); +// c = __connect_nonblock(); +// redisCommand(c,"PING"); +// redisDisconnect(c); +// test_cond(redisBufferWrite(c,NULL) == REDIS_ERR && +// strncmp(c->error,"write:",6) == 0); +// redisFree(c); +// +// test("Process callbacks in the right sequence: "); +// c = __connect_nonblock(); +// redisCommandWithCallback(c,__test_reply_callback,(void*)1,"PING"); +// redisCommandWithCallback(c,__test_reply_callback,(void*)2,"PING"); +// redisCommandWithCallback(c,__test_reply_callback,(void*)3,"PING"); +// +// /* Write output buffer */ +// wdone = 0; +// while(!wdone) { +// usleep(500); +// redisBufferWrite(c,&wdone); +// } +// +// /* Read until at least one callback is executed (the 3 replies will +// * arrive in a single packet, causing all callbacks to be executed in +// * a single pass). */ +// while(__test_callback_flags == 0) { +// assert(redisBufferRead(c) == REDIS_OK); +// redisProcessCallbacks(c); +// } +// test_cond(__test_callback_flags == 0x010203); +// redisFree(c); +// +// test("redisDisconnect executes pending callbacks with NULL reply: "); +// c = __connect_nonblock(); +// redisSetDisconnectCallback(c,__test_callback,(void*)1); +// redisCommandWithCallback(c,__test_reply_callback,(void*)2,"PING"); +// redisDisconnect(c); +// test_cond(__test_callback_flags == 0x0201); +// redisFree(c); +// } int main(void) { test_format_commands(); test_blocking_connection(); test_reply_reader(); - test_nonblocking_connection(); + // test_nonblocking_connection(); test_throughput(); cleanup(); |