diff options
author | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2010-11-19 12:37:04 +0100 |
---|---|---|
committer | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2010-11-19 12:37:06 +0100 |
commit | 650df0f98241ff1871c91ca4602ace160ca9d359 (patch) | |
tree | 02c7ba926f3639e41fcecbdf96ef3e5fd264c803 /test.c | |
parent | 74254a3b392ee391cd6e4667370d0c7963bb986b (diff) |
Don't do a write(2) after QUIT
This causes non-deterministic error messages because sometimes the
socket will already be closed and sometimes it is yet to be closed.
Diffstat (limited to 'test.c')
-rw-r--r-- | test.c | 22 |
1 files changed, 9 insertions, 13 deletions
@@ -178,24 +178,20 @@ static void test_blocking_connection() { if (major >= 2 && minor > 0) { /* > 2.0 returns OK on QUIT and read() should be issued once more * to know the descriptor is at EOF. */ - test_cond(strcasecmp(reply->str,"OK") == 0 && redisCommand(c,"PING") == NULL); + test_cond(strcasecmp(reply->str,"OK") == 0 && + redisGetReply(c,(void**)&reply) == REDIS_ERR); freeReplyObject(reply); } else { test_cond(reply == NULL); } - /* Two conditions may happen, depending on the type of connection. - * When connected via TCP, the socket will not yet be aware of the closed - * connection and the write(2) call will succeed, but the read(2) will - * result in an EOF. When connected via Unix sockets, the socket will be - * immediately aware that it was closed and fail on the write(2) call. */ - if (use_unix) { - assert(c->err == REDIS_ERR_IO && - strcmp(c->errstr,"Broken pipe") == 0); - } else { - assert(c->err == REDIS_ERR_EOF && - strcmp(c->errstr,"Server closed the connection") == 0); - } + /* On 2.0, QUIT will cause the connection to be closed immediately and + * the read(2) for the reply on QUIT will set the error to EOF. + * On >2.0, QUIT will return with OK and another read(2) needed to be + * issued to find out the socket was closed by the server. In both + * conditions, the error will be set to EOF. */ + assert(c->err == REDIS_ERR_EOF && + strcmp(c->errstr,"Server closed the connection") == 0); /* Clean up context and reconnect again */ redisFree(c); |