From b432508f213b3914d9887d1444fab209477a8337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= Date: Wed, 18 Dec 2024 12:46:21 +0100 Subject: [PATCH] Update tests to use non-const connect callbacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Björn Svensson --- examples/async-glib.c | 2 +- examples/async-libev.c | 2 +- examples/async-libevent-tls.c | 2 +- examples/async-libevent.c | 2 +- examples/async-libhv.c | 2 +- examples/async-libsdevent.c | 2 +- examples/async-libuv.c | 2 +- examples/cluster-async-tls.c | 2 +- examples/cluster-async.c | 2 +- examples/cluster-clientside-caching-async.c | 9 ++++--- tests/client_test.c | 2 +- tests/clusterclient_async.c | 2 +- tests/ct_async.c | 12 +--------- tests/ct_async_glib.c | 2 +- tests/ct_async_libev.c | 2 +- tests/ct_async_libuv.c | 2 +- tests/ct_connection.c | 26 ++++++++++++--------- tests/ct_out_of_memory_handling.c | 10 +++++--- tests/ct_pipeline.c | 10 +++++--- tests/ct_specific_nodes.c | 26 ++++++++++++--------- 20 files changed, 63 insertions(+), 58 deletions(-) diff --git a/examples/async-glib.c b/examples/async-glib.c index d4b3a934..ea70a784 100644 --- a/examples/async-glib.c +++ b/examples/async-glib.c @@ -8,7 +8,7 @@ static GMainLoop *mainloop; static void -connect_cb(const valkeyAsyncContext *ac G_GNUC_UNUSED, +connect_cb(valkeyAsyncContext *ac G_GNUC_UNUSED, int status) { if (status != VALKEY_OK) { g_printerr("Failed to connect: %s\n", ac->errstr); diff --git a/examples/async-libev.c b/examples/async-libev.c index 31a49a05..37c85604 100644 --- a/examples/async-libev.c +++ b/examples/async-libev.c @@ -18,7 +18,7 @@ void getCallback(valkeyAsyncContext *c, void *r, void *privdata) { valkeyAsyncDisconnect(c); } -void connectCallback(const valkeyAsyncContext *c, int status) { +void connectCallback(valkeyAsyncContext *c, int status) { if (status != VALKEY_OK) { printf("Error: %s\n", c->errstr); return; diff --git a/examples/async-libevent-tls.c b/examples/async-libevent-tls.c index 7f1c9d5e..cf42ee3a 100644 --- a/examples/async-libevent-tls.c +++ b/examples/async-libevent-tls.c @@ -19,7 +19,7 @@ void getCallback(valkeyAsyncContext *c, void *r, void *privdata) { valkeyAsyncDisconnect(c); } -void connectCallback(const valkeyAsyncContext *c, int status) { +void connectCallback(valkeyAsyncContext *c, int status) { if (status != VALKEY_OK) { printf("Error: %s\n", c->errstr); return; diff --git a/examples/async-libevent.c b/examples/async-libevent.c index c1f0d296..943c05a0 100644 --- a/examples/async-libevent.c +++ b/examples/async-libevent.c @@ -22,7 +22,7 @@ void getCallback(valkeyAsyncContext *c, void *r, void *privdata) { valkeyAsyncDisconnect(c); } -void connectCallback(const valkeyAsyncContext *c, int status) { +void connectCallback(valkeyAsyncContext *c, int status) { if (status != VALKEY_OK) { printf("Error: %s\n", c->errstr); return; diff --git a/examples/async-libhv.c b/examples/async-libhv.c index 44c1fbbc..9d7ba91d 100644 --- a/examples/async-libhv.c +++ b/examples/async-libhv.c @@ -30,7 +30,7 @@ void debugCallback(valkeyAsyncContext *c, void *r, void *privdata) { valkeyAsyncDisconnect(c); } -void connectCallback(const valkeyAsyncContext *c, int status) { +void connectCallback(valkeyAsyncContext *c, int status) { if (status != VALKEY_OK) { printf("Error: %s\n", c->errstr); return; diff --git a/examples/async-libsdevent.c b/examples/async-libsdevent.c index e6e25626..18632542 100644 --- a/examples/async-libsdevent.c +++ b/examples/async-libsdevent.c @@ -33,7 +33,7 @@ void getCallback(valkeyAsyncContext *c, void *r, void *privdata) { valkeyAsyncCommand(c, debugCallback, NULL, "DEBUG SLEEP %f", 1.5); } -void connectCallback(const valkeyAsyncContext *c, int status) { +void connectCallback(valkeyAsyncContext *c, int status) { if (status != VALKEY_OK) { printf("connect error: %s\n", c->errstr); return; diff --git a/examples/async-libuv.c b/examples/async-libuv.c index 4b3c3501..7adf3204 100644 --- a/examples/async-libuv.c +++ b/examples/async-libuv.c @@ -33,7 +33,7 @@ void getCallback(valkeyAsyncContext *c, void *r, void *privdata) { valkeyAsyncCommand(c, debugCallback, NULL, "DEBUG SLEEP %f", 1.5); } -void connectCallback(const valkeyAsyncContext *c, int status) { +void connectCallback(valkeyAsyncContext *c, int status) { if (status != VALKEY_OK) { printf("connect error: %s\n", c->errstr); return; diff --git a/examples/cluster-async-tls.c b/examples/cluster-async-tls.c index 00200f68..87a346db 100644 --- a/examples/cluster-async-tls.c +++ b/examples/cluster-async-tls.c @@ -34,7 +34,7 @@ void setCallback(valkeyClusterAsyncContext *cc, void *r, void *privdata) { printf("privdata: %s reply: %s\n", (char *)privdata, reply->str); } -void connectCallback(const valkeyAsyncContext *ac, int status) { +void connectCallback(valkeyAsyncContext *ac, int status) { if (status != VALKEY_OK) { printf("Error: %s\n", ac->errstr); return; diff --git a/examples/cluster-async.c b/examples/cluster-async.c index f2d9c282..9f52ed81 100644 --- a/examples/cluster-async.c +++ b/examples/cluster-async.c @@ -30,7 +30,7 @@ void setCallback(valkeyClusterAsyncContext *cc, void *r, void *privdata) { printf("privdata: %s reply: %s\n", (char *)privdata, reply->str); } -void connectCallback(const valkeyAsyncContext *ac, int status) { +void connectCallback(valkeyAsyncContext *ac, int status) { if (status != VALKEY_OK) { printf("Error: %s\n", ac->errstr); return; diff --git a/examples/cluster-clientside-caching-async.c b/examples/cluster-clientside-caching-async.c index f1c11181..4b8052fc 100644 --- a/examples/cluster-clientside-caching-async.c +++ b/examples/cluster-clientside-caching-async.c @@ -22,10 +22,9 @@ void getCallback1(valkeyClusterAsyncContext *acc, void *r, void *privdata); void getCallback2(valkeyClusterAsyncContext *acc, void *r, void *privdata); void modifyKey(const char *key, const char *value); -/* The connect callback enables RESP3 and client tracking. - The non-const connect callback is used since we want to - set the push callback in the libvalkey context. */ -void connectCallbackNC(valkeyAsyncContext *ac, int status) { +/* The connect callback enables RESP3 and client tracking, + * and sets the push callback in the libvalkey context. */ +void connectCallback(valkeyAsyncContext *ac, int status) { assert(status == VALKEY_OK); valkeyAsyncSetPushCallback(ac, pushCallback); valkeyAsyncCommand(ac, NULL, NULL, "HELLO 3"); @@ -147,7 +146,7 @@ int main(int argc, char **argv) { assert(acc); int status; - status = valkeyClusterAsyncSetConnectCallbackNC(acc, connectCallbackNC); + status = valkeyClusterAsyncSetConnectCallback(acc, connectCallback); assert(status == VALKEY_OK); status = valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); assert(status == VALKEY_OK); diff --git a/tests/client_test.c b/tests/client_test.c index 6c1301a0..3ad528b0 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -2173,7 +2173,7 @@ static valkeyAsyncContext *do_aconnect(struct config config, astest_no testno) { c->data = &astest; c->dataCleanup = asCleanup; valkeyPollAttach(c); - valkeyAsyncSetConnectCallbackNC(c, connectCallback); + valkeyAsyncSetConnectCallback(c, connectCallback); valkeyAsyncSetDisconnectCallback(c, disconnectCallback); return c; } diff --git a/tests/clusterclient_async.c b/tests/clusterclient_async.c index f1449004..d19f68d6 100644 --- a/tests/clusterclient_async.c +++ b/tests/clusterclient_async.c @@ -207,7 +207,7 @@ void eventCallback(const valkeyClusterContext *cc, int event, void *privdata) { printf("Event: %s\n", e); } -void connectCallback(const valkeyAsyncContext *ac, int status) { +void connectCallback(valkeyAsyncContext *ac, int status) { const char *s = ""; if (status != VALKEY_OK) s = "failed to "; diff --git a/tests/ct_async.c b/tests/ct_async.c index 99b4d438..6148fdb3 100644 --- a/tests/ct_async.c +++ b/tests/ct_async.c @@ -23,19 +23,11 @@ void setCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) { ASSERT_MSG(reply != NULL, acc->errstr); } -void connectCallback(const valkeyAsyncContext *ac, int status) { +void connectCallback(valkeyAsyncContext *ac, int status) { ASSERT_MSG(status == VALKEY_OK, ac->errstr); printf("Connected to %s:%d\n", ac->c.tcp.host, ac->c.tcp.port); } -void connectCallbackNC(valkeyAsyncContext *ac, int status) { - UNUSED(ac); - UNUSED(status); - /* The testcase expects a failure during registration of this - non-const connect callback and it should never be called. */ - assert(0); -} - void disconnectCallback(const valkeyAsyncContext *ac, int status) { ASSERT_MSG(status == VALKEY_OK, ac->errstr); printf("Disconnected from %s:%d\n", ac->c.tcp.host, ac->c.tcp.port); @@ -77,8 +69,6 @@ int main(void) { assert(status == VALKEY_OK); status = valkeyClusterAsyncSetConnectCallback(acc, connectCallback); assert(status == VALKEY_ERR); /* Re-registration not accepted */ - status = valkeyClusterAsyncSetConnectCallbackNC(acc, connectCallbackNC); - assert(status == VALKEY_ERR); /* Re-registration not accepted */ status = valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); assert(status == VALKEY_OK); diff --git a/tests/ct_async_glib.c b/tests/ct_async_glib.c index 8aafca4f..e6d305f3 100644 --- a/tests/ct_async_glib.c +++ b/tests/ct_async_glib.c @@ -24,7 +24,7 @@ void getCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) { g_main_loop_quit(mainloop); } -void connectCallback(const valkeyAsyncContext *ac, int status) { +void connectCallback(valkeyAsyncContext *ac, int status) { ASSERT_MSG(status == VALKEY_OK, ac->errstr); printf("Connected to %s:%d\n", ac->c.tcp.host, ac->c.tcp.port); } diff --git a/tests/ct_async_libev.c b/tests/ct_async_libev.c index f6522475..292df507 100644 --- a/tests/ct_async_libev.c +++ b/tests/ct_async_libev.c @@ -21,7 +21,7 @@ void getCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) { valkeyClusterAsyncDisconnect(acc); } -void connectCallback(const valkeyAsyncContext *ac, int status) { +void connectCallback(valkeyAsyncContext *ac, int status) { ASSERT_MSG(status == VALKEY_OK, ac->errstr); printf("Connected to %s:%d\n", ac->c.tcp.host, ac->c.tcp.port); } diff --git a/tests/ct_async_libuv.c b/tests/ct_async_libuv.c index 4bc0b5bb..b2771a1c 100644 --- a/tests/ct_async_libuv.c +++ b/tests/ct_async_libuv.c @@ -22,7 +22,7 @@ void getCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) { valkeyClusterAsyncDisconnect(acc); } -void connectCallback(const valkeyAsyncContext *ac, int status) { +void connectCallback(valkeyAsyncContext *ac, int status) { ASSERT_MSG(status == VALKEY_OK, ac->errstr); printf("Connected to %s:%d\n", ac->c.tcp.host, ac->c.tcp.port); } diff --git a/tests/ct_connection.c b/tests/ct_connection.c index ef8f35dc..7dff73e7 100644 --- a/tests/ct_connection.c +++ b/tests/ct_connection.c @@ -313,7 +313,11 @@ typedef struct ExpectedResult { } ExpectedResult; // Callback for Valkey connects and disconnects -void callbackExpectOk(const valkeyAsyncContext *ac, int status) { +void connectCallback(valkeyAsyncContext *ac, int status) { + UNUSED(ac); + assert(status == VALKEY_OK); +} +void disconnectCallback(const valkeyAsyncContext *ac, int status) { UNUSED(ac); assert(status == VALKEY_OK); } @@ -345,8 +349,8 @@ void commandCallback(valkeyClusterAsyncContext *cc, void *r, void *privdata) { void test_async_password_ok(void) { valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(); assert(acc); - valkeyClusterAsyncSetConnectCallback(acc, callbackExpectOk); - valkeyClusterAsyncSetDisconnectCallback(acc, callbackExpectOk); + valkeyClusterAsyncSetConnectCallback(acc, connectCallback); + valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); valkeyClusterSetOptionAddNodes(acc->cc, CLUSTER_NODE_WITH_PASSWORD); valkeyClusterSetOptionPassword(acc->cc, CLUSTER_PASSWORD); @@ -404,8 +408,8 @@ void test_async_password_wrong(void) { void test_async_password_missing(void) { valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(); assert(acc); - valkeyClusterAsyncSetConnectCallback(acc, callbackExpectOk); - valkeyClusterAsyncSetDisconnectCallback(acc, callbackExpectOk); + valkeyClusterAsyncSetConnectCallback(acc, connectCallback); + valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); valkeyClusterSetOptionAddNodes(acc->cc, CLUSTER_NODE_WITH_PASSWORD); // Password not configured @@ -434,8 +438,8 @@ void test_async_username_ok(void) { // Connect to the cluster using username and password valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(); assert(acc); - valkeyClusterAsyncSetConnectCallback(acc, callbackExpectOk); - valkeyClusterAsyncSetDisconnectCallback(acc, callbackExpectOk); + valkeyClusterAsyncSetConnectCallback(acc, connectCallback); + valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); valkeyClusterSetOptionAddNodes(acc->cc, CLUSTER_NODE_WITH_PASSWORD); valkeyClusterSetOptionUsername(acc->cc, "missing-user"); valkeyClusterSetOptionPassword(acc->cc, CLUSTER_PASSWORD); @@ -478,14 +482,14 @@ void test_async_multicluster(void) { valkeyClusterAsyncContext *acc1 = valkeyClusterAsyncContextInit(); assert(acc1); - valkeyClusterAsyncSetConnectCallback(acc1, callbackExpectOk); - valkeyClusterAsyncSetDisconnectCallback(acc1, callbackExpectOk); + valkeyClusterAsyncSetConnectCallback(acc1, connectCallback); + valkeyClusterAsyncSetDisconnectCallback(acc1, disconnectCallback); valkeyClusterSetOptionAddNodes(acc1->cc, CLUSTER_NODE); valkeyClusterAsyncContext *acc2 = valkeyClusterAsyncContextInit(); assert(acc2); - valkeyClusterAsyncSetConnectCallback(acc2, callbackExpectOk); - valkeyClusterAsyncSetDisconnectCallback(acc2, callbackExpectOk); + valkeyClusterAsyncSetConnectCallback(acc2, connectCallback); + valkeyClusterAsyncSetDisconnectCallback(acc2, disconnectCallback); valkeyClusterSetOptionAddNodes(acc2->cc, CLUSTER_NODE_WITH_PASSWORD); valkeyClusterSetOptionPassword(acc2->cc, CLUSTER_PASSWORD); diff --git a/tests/ct_out_of_memory_handling.c b/tests/ct_out_of_memory_handling.c index 53b8a718..3d7de08c 100644 --- a/tests/ct_out_of_memory_handling.c +++ b/tests/ct_out_of_memory_handling.c @@ -453,7 +453,11 @@ typedef struct ExpectedResult { } ExpectedResult; // Callback for Valkey connects and disconnects -void callbackExpectOk(const valkeyAsyncContext *ac, int status) { +void connectCallback(valkeyAsyncContext *ac, int status) { + UNUSED(ac); + assert(status == VALKEY_OK); +} +void disconnectCallback(const valkeyAsyncContext *ac, int status) { UNUSED(ac); assert(status == VALKEY_OK); } @@ -501,9 +505,9 @@ void test_alloc_failure_handling_async(void) { // Set callbacks { prepare_allocation_test_async(acc, 0); - result = valkeyClusterAsyncSetConnectCallback(acc, callbackExpectOk); + result = valkeyClusterAsyncSetConnectCallback(acc, connectCallback); assert(result == VALKEY_OK); - result = valkeyClusterAsyncSetDisconnectCallback(acc, callbackExpectOk); + result = valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); assert(result == VALKEY_OK); } diff --git a/tests/ct_pipeline.c b/tests/ct_pipeline.c index d5a062dd..5fe8cc54 100644 --- a/tests/ct_pipeline.c +++ b/tests/ct_pipeline.c @@ -68,7 +68,11 @@ typedef struct ExpectedResult { } ExpectedResult; // Callback for Valkey connects and disconnects -void callbackExpectOk(const valkeyAsyncContext *ac, int status) { +void connectCallback(valkeyAsyncContext *ac, int status) { + UNUSED(ac); + assert(status == VALKEY_OK); +} +void disconnectCallback(const valkeyAsyncContext *ac, int status) { UNUSED(ac); assert(status == VALKEY_OK); } @@ -93,8 +97,8 @@ void commandCallback(valkeyClusterAsyncContext *cc, void *r, void *privdata) { void test_async_pipeline(void) { valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(); assert(acc); - valkeyClusterAsyncSetConnectCallback(acc, callbackExpectOk); - valkeyClusterAsyncSetDisconnectCallback(acc, callbackExpectOk); + valkeyClusterAsyncSetConnectCallback(acc, connectCallback); + valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); valkeyClusterSetOptionAddNodes(acc->cc, CLUSTER_NODE); int status; diff --git a/tests/ct_specific_nodes.c b/tests/ct_specific_nodes.c index 22223be7..8793cb41 100644 --- a/tests/ct_specific_nodes.c +++ b/tests/ct_specific_nodes.c @@ -277,7 +277,11 @@ typedef struct ExpectedResult { } ExpectedResult; // Callback for Valkey connects and disconnects -void callbackExpectOk(const valkeyAsyncContext *ac, int status) { +void connectCallback(valkeyAsyncContext *ac, int status) { + UNUSED(ac); + assert(status == VALKEY_OK); +} +void disconnectCallback(const valkeyAsyncContext *ac, int status) { UNUSED(ac); assert(status == VALKEY_OK); } @@ -318,8 +322,8 @@ void test_async_to_single_node(void) { valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(); assert(acc); - valkeyClusterAsyncSetConnectCallback(acc, callbackExpectOk); - valkeyClusterAsyncSetDisconnectCallback(acc, callbackExpectOk); + valkeyClusterAsyncSetConnectCallback(acc, connectCallback); + valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); valkeyClusterSetOptionAddNodes(acc->cc, CLUSTER_NODE); valkeyClusterSetOptionMaxRetry(acc->cc, 1); valkeyClusterSetOptionRouteUseSlots(acc->cc); @@ -351,8 +355,8 @@ void test_async_formatted_to_single_node(void) { valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(); assert(acc); - valkeyClusterAsyncSetConnectCallback(acc, callbackExpectOk); - valkeyClusterAsyncSetDisconnectCallback(acc, callbackExpectOk); + valkeyClusterAsyncSetConnectCallback(acc, connectCallback); + valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); valkeyClusterSetOptionAddNodes(acc->cc, CLUSTER_NODE); valkeyClusterSetOptionMaxRetry(acc->cc, 1); valkeyClusterSetOptionRouteUseSlots(acc->cc); @@ -385,8 +389,8 @@ void test_async_command_argv_to_single_node(void) { valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(); assert(acc); - valkeyClusterAsyncSetConnectCallback(acc, callbackExpectOk); - valkeyClusterAsyncSetDisconnectCallback(acc, callbackExpectOk); + valkeyClusterAsyncSetConnectCallback(acc, connectCallback); + valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); valkeyClusterSetOptionAddNodes(acc->cc, CLUSTER_NODE); valkeyClusterSetOptionMaxRetry(acc->cc, 1); valkeyClusterSetOptionRouteUseSlots(acc->cc); @@ -419,8 +423,8 @@ void test_async_to_all_nodes(void) { valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(); assert(acc); - valkeyClusterAsyncSetConnectCallback(acc, callbackExpectOk); - valkeyClusterAsyncSetDisconnectCallback(acc, callbackExpectOk); + valkeyClusterAsyncSetConnectCallback(acc, connectCallback); + valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); valkeyClusterSetOptionAddNodes(acc->cc, CLUSTER_NODE); valkeyClusterSetOptionMaxRetry(acc->cc, 1); valkeyClusterSetOptionRouteUseSlots(acc->cc); @@ -461,8 +465,8 @@ void test_async_transaction(void) { valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(); assert(acc); - valkeyClusterAsyncSetConnectCallback(acc, callbackExpectOk); - valkeyClusterAsyncSetDisconnectCallback(acc, callbackExpectOk); + valkeyClusterAsyncSetConnectCallback(acc, connectCallback); + valkeyClusterAsyncSetDisconnectCallback(acc, disconnectCallback); valkeyClusterSetOptionAddNodes(acc->cc, CLUSTER_NODE); valkeyClusterSetOptionMaxRetry(acc->cc, 1); valkeyClusterSetOptionRouteUseSlots(acc->cc);