| 1014 | } |
| 1015 | |
| 1016 | static void test_blocking_io_errors(struct config config) { |
| 1017 | redisContext *c; |
| 1018 | redisReply *reply; |
| 1019 | void *_reply; |
| 1020 | int major, minor; |
| 1021 | |
| 1022 | /* Connect to target given by config. */ |
| 1023 | c = do_connect(config); |
| 1024 | get_redis_version(c, &major, &minor); |
| 1025 | |
| 1026 | test("Returns I/O error when the connection is lost: "); |
| 1027 | reply = redisCommand(c,"QUIT"); |
| 1028 | if (major > 2 || (major == 2 && minor > 0)) { |
| 1029 | /* > 2.0 returns OK on QUIT and read() should be issued once more |
| 1030 | * to know the descriptor is at EOF. */ |
| 1031 | test_cond(strcasecmp(reply->str,"OK") == 0 && |
| 1032 | redisGetReply(c,&_reply) == REDIS_ERR); |
| 1033 | freeReplyObject(reply); |
| 1034 | } else { |
| 1035 | test_cond(reply == NULL); |
| 1036 | } |
| 1037 | |
| 1038 | #ifndef _WIN32 |
| 1039 | /* On 2.0, QUIT will cause the connection to be closed immediately and |
| 1040 | * the read(2) for the reply on QUIT will set the error to EOF. |
| 1041 | * On >2.0, QUIT will return with OK and another read(2) needed to be |
| 1042 | * issued to find out the socket was closed by the server. In both |
| 1043 | * conditions, the error will be set to EOF. */ |
| 1044 | assert(c->err == REDIS_ERR_EOF && |
| 1045 | strcmp(c->errstr,"Server closed the connection") == 0); |
| 1046 | #endif |
| 1047 | redisFree(c); |
| 1048 | |
| 1049 | c = do_connect(config); |
| 1050 | test("Returns I/O error on socket timeout: "); |
| 1051 | struct timeval tv = { 0, 1000 }; |
| 1052 | assert(redisSetTimeout(c,tv) == REDIS_OK); |
| 1053 | int respcode = redisGetReply(c,&_reply); |
| 1054 | #ifndef _WIN32 |
| 1055 | test_cond(respcode == REDIS_ERR && c->err == REDIS_ERR_IO && errno == EAGAIN); |
| 1056 | #else |
| 1057 | test_cond(respcode == REDIS_ERR && c->err == REDIS_ERR_TIMEOUT); |
| 1058 | #endif |
| 1059 | redisFree(c); |
| 1060 | } |
| 1061 | |
| 1062 | static void test_invalid_timeout_errors(struct config config) { |
| 1063 | redisContext *c; |
no test coverage detected