Add regression test for issue #945
This commit is contained in:
parent
4b901d44ad
commit
2ccef30f3e
47
test.c
47
test.c
@ -1901,14 +1901,16 @@ static void test_monitor(struct config config) {
|
|||||||
|
|
||||||
/* tests for async api using polling adapter, requires no extra libraries*/
|
/* tests for async api using polling adapter, requires no extra libraries*/
|
||||||
|
|
||||||
/* a static context for the async tests */
|
/* enum for the test cases, the callbacks have different logic based on them */
|
||||||
typedef enum astest_no
|
typedef enum astest_no
|
||||||
{
|
{
|
||||||
ASTEST_CONNECT=0,
|
ASTEST_CONNECT=0,
|
||||||
ASTEST_CONN_TIMEOUT,
|
ASTEST_CONN_TIMEOUT,
|
||||||
ASTEST_PINGPONG
|
ASTEST_PINGPONG,
|
||||||
|
ASTEST_PINGPONG_TIMEOUT
|
||||||
}astest_no;
|
}astest_no;
|
||||||
|
|
||||||
|
/* a static context for the async tests */
|
||||||
struct _astest {
|
struct _astest {
|
||||||
redisAsyncContext *ac;
|
redisAsyncContext *ac;
|
||||||
astest_no testno;
|
astest_no testno;
|
||||||
@ -1922,6 +1924,17 @@ struct _astest {
|
|||||||
char errstr[256];
|
char errstr[256];
|
||||||
};
|
};
|
||||||
static struct _astest astest;
|
static struct _astest astest;
|
||||||
|
|
||||||
|
static void asSleep(int ms)
|
||||||
|
{
|
||||||
|
#if _MSC_VER
|
||||||
|
Sleep(ms);
|
||||||
|
#else
|
||||||
|
usleep(ms*1000);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* async callbacks */
|
||||||
static void asCleanup(void* data)
|
static void asCleanup(void* data)
|
||||||
{
|
{
|
||||||
struct _astest *t = (struct _astest *)data;
|
struct _astest *t = (struct _astest *)data;
|
||||||
@ -1961,6 +1974,18 @@ static void commandCallback(struct redisAsyncContext *ac, void* _reply, void* _p
|
|||||||
test_cond(reply != NULL && reply->type == REDIS_REPLY_STATUS && strcmp(reply->str, "PONG") == 0);
|
test_cond(reply != NULL && reply->type == REDIS_REPLY_STATUS && strcmp(reply->str, "PONG") == 0);
|
||||||
redisAsyncFree(ac);
|
redisAsyncFree(ac);
|
||||||
}
|
}
|
||||||
|
if (t->testno == ASTEST_PINGPONG_TIMEOUT)
|
||||||
|
{
|
||||||
|
/* two ping pongs */
|
||||||
|
assert(reply != NULL && reply->type == REDIS_REPLY_STATUS && strcmp(reply->str, "PONG") == 0);
|
||||||
|
if (++t->counter == 1) {
|
||||||
|
int status = redisAsyncCommand(ac, commandCallback, NULL, "PING");
|
||||||
|
assert(status == REDIS_OK);
|
||||||
|
} else {
|
||||||
|
test_cond(reply != NULL && reply->type == REDIS_REPLY_STATUS && strcmp(reply->str, "PONG") == 0);
|
||||||
|
redisAsyncFree(ac);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static redisAsyncContext *do_aconnect(struct config config, astest_no testno)
|
static redisAsyncContext *do_aconnect(struct config config, astest_no testno)
|
||||||
@ -2062,10 +2087,28 @@ static void test_async_polling(struct config config) {
|
|||||||
redisPollTick(c, 0.1);
|
redisPollTick(c, 0.1);
|
||||||
status = redisAsyncCommand(c, commandCallback, NULL, "PING");
|
status = redisAsyncCommand(c, commandCallback, NULL, "PING");
|
||||||
assert(status == REDIS_OK);
|
assert(status == REDIS_OK);
|
||||||
|
while(astest.ac)
|
||||||
|
redisPollTick(c, 0.1);
|
||||||
|
|
||||||
|
/* Test a ping/pong after connection that didn't time out.
|
||||||
|
* see https://github.com/redis/hiredis/issues/945
|
||||||
|
*/
|
||||||
|
if (config.type == CONN_TCP || config.type == CONN_SSL) {
|
||||||
|
test("Async PING/PONG after connect timeout: ");
|
||||||
|
config.tcp.timeout.tv_usec = 10000; /* 10ms */
|
||||||
|
c = do_aconnect(config, ASTEST_PINGPONG_TIMEOUT);
|
||||||
|
while(astest.connected == 0)
|
||||||
|
redisPollTick(c, 0.1);
|
||||||
|
/* sleep 0.1 s, allowing old timeout to arrive */
|
||||||
|
asSleep(10);
|
||||||
|
status = redisAsyncCommand(c, commandCallback, NULL, "PING");
|
||||||
|
assert(status == REDIS_OK);
|
||||||
while(astest.ac)
|
while(astest.ac)
|
||||||
redisPollTick(c, 0.1);
|
redisPollTick(c, 0.1);
|
||||||
config = defaultconfig;
|
config = defaultconfig;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
/* End of Async polling_adapter driven tests */
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
struct config cfg = {
|
struct config cfg = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user