diff options
author | Alessio M <masariello@gmail.com> | 2020-09-04 09:31:47 +0100 |
---|---|---|
committer | Alessio M <masariello@gmail.com> | 2020-09-04 09:31:47 +0100 |
commit | d7b1d21e807f8a90a086b2ef5cea9b707d4cc858 (patch) | |
tree | 748b00a48a8b625f1dca22ae4cc5721ab7de87c5 /test.c | |
parent | 07c3618ffe7912c2ebc589ea45501c687a19cf2c (diff) | |
parent | fb0e6c0dd9affd5728c6e0a6423f5dcb7b207947 (diff) |
Merge branch 'master' of github.com:redis/hiredis
Diffstat (limited to 'test.c')
-rw-r--r-- | test.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -49,6 +49,10 @@ struct config { } ssl; }; +struct privdata { + int dtor_counter; +}; + #ifdef HIREDIS_TEST_SSL redisSSLContext *_ssl_ctx = NULL; #endif @@ -786,6 +790,27 @@ static void test_resp3_push_options(struct config config) { redisAsyncFree(ac); } +void free_privdata(void *privdata) { + struct privdata *data = privdata; + data->dtor_counter++; +} + +static void test_privdata_hooks(struct config config) { + struct privdata data = {0}; + redisOptions options; + redisContext *c; + + test("We can use redisOptions to set privdata: "); + options = get_redis_tcp_options(config); + REDIS_OPTIONS_SET_PRIVDATA(&options, &data, free_privdata); + assert((c = redisConnectWithOptions(&options)) != NULL); + test_cond(c->privdata == &data); + + test("Our privdata destructor fires when we free the context: "); + redisFree(c); + test_cond(data.dtor_counter == 1); +} + static void test_blocking_connection(struct config config) { redisContext *c; redisReply *reply; @@ -871,6 +896,8 @@ static void test_blocking_connection(struct config config) { if (major >= 6) test_resp3_push_handler(c); test_resp3_push_options(config); + test_privdata_hooks(config); + disconnect(c, 0); } |