summaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2010-09-19 19:01:31 +0200
committerPieter Noordhuis <pcnoordhuis@gmail.com>2010-09-19 19:01:31 +0200
commit62c8054dbe5d590a7f2d36e4e5176996215e9aa7 (patch)
tree2a194ad7bf812dbb300f3084614ae6a4bc7e0fef /test.c
parent457cdbf7c5f98c7ac5b4d727a1bad0c041f7cc66 (diff)
Clean up when there is an I/O error
Diffstat (limited to 'test.c')
-rw-r--r--test.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/test.c b/test.c
index cec8ada..2824159 100644
--- a/test.c
+++ b/test.c
@@ -15,20 +15,31 @@ long long usec(void) {
return (((long long)tv.tv_sec)*1000000)+tv.tv_usec;
}
+void connect(int *fd) {
+ redisReply *reply = redisConnect(fd, "127.0.0.1", 6379);
+ if (reply != NULL) {
+ printf("Connection error: %s", reply->reply);
+ exit(1);
+ }
+}
+
int main(void) {
int fd;
int i, fails = 0;
long long t1, t2;
redisReply *reply;
+ connect(&fd);
- reply = redisConnect(&fd, "127.0.0.1", 6379);
- if (reply != NULL) {
- printf("Connection error: %s", reply->reply);
- exit(1);
- }
+ /* test 0 */
+ printf("#0 Returns I/O error when the connection is lost: ");
+ reply = redisCommand(fd,"QUIT");
+ test_cond(reply->type == REDIS_REPLY_ERROR &&
+ strcasecmp(reply->reply,"i/o error") == 0);
+ freeReplyObject(reply);
+ connect(&fd); /* reconnect */
/* test 1 */
- printf("\n#1 Is able to deliver commands: ");
+ printf("#1 Is able to deliver commands: ");
reply = redisCommand(fd,"PING");
test_cond(reply->type == REDIS_REPLY_STRING &&
strcasecmp(reply->reply,"pong") == 0)