summaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2010-10-18 15:39:56 +0200
committerPieter Noordhuis <pcnoordhuis@gmail.com>2010-10-18 15:39:56 +0200
commita68cb9686e4431951897e30d87b42ebb6a8faae5 (patch)
tree92760ec2c6e018dd0aeb7c9e7a7a07fad2d0e81a /test.c
parent634314f386fc7ac39ae21724685ec6252e30e7a6 (diff)
Tests for context callbacks in non-blocking mode
Diffstat (limited to 'test.c')
-rw-r--r--test.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/test.c b/test.c
index 0b028fc..09bc32d 100644
--- a/test.c
+++ b/test.c
@@ -193,9 +193,46 @@ static void cleanup() {
redisFree(c);
}
+static long __test_callback_flags = 0;
+static void __test_callback(redisContext *c, const void *privdata) {
+ ((void)c);
+ /* Shift to detect execution order */
+ __test_callback_flags <<= 8;
+ __test_callback_flags |= (long)privdata;
+}
+
+static void test_nonblocking_connection() {
+ redisContext *c;
+
+ __test_callback_flags = 0;
+ test("Calls command callback when command is issued: ");
+ c = redisConnectNonBlock("127.0.0.1", 6379, NULL);
+ redisSetCommandCallback(c,__test_callback,(const void*)1);
+ redisCommand(c,"PING");
+ test_cond(__test_callback_flags == 1);
+ redisFree(c);
+
+ __test_callback_flags = 0;
+ test("Calls disconnect callback on redisDisconnect: ");
+ c = redisConnectNonBlock("127.0.0.1", 6379, NULL);
+ redisSetDisconnectCallback(c,__test_callback,(const void*)2);
+ redisDisconnect(c);
+ test_cond(__test_callback_flags == 2);
+ redisFree(c);
+
+ __test_callback_flags = 0;
+ test("Calls disconnect callback and free callback on redisFree: ");
+ c = redisConnectNonBlock("127.0.0.1", 6379, NULL);
+ redisSetDisconnectCallback(c,__test_callback,(const void*)2);
+ redisSetFreeCallback(c,__test_callback,(const void*)4);
+ redisFree(c);
+ test_cond(__test_callback_flags == ((2 << 8) | 4));
+}
+
int main(void) {
test_blocking_connection();
test_reply_reader();
+ test_nonblocking_connection();
test_throughput();
cleanup();