Skip to content

Commit

Permalink
Update tests to use non-const connect callbacks
Browse files Browse the repository at this point in the history
Signed-off-by: Björn Svensson <[email protected]>
  • Loading branch information
bjosv committed Dec 18, 2024
1 parent ac60a12 commit b432508
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 58 deletions.
2 changes: 1 addition & 1 deletion examples/async-glib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/async-libev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/async-libevent-tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/async-libevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/async-libhv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/async-libsdevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/async-libuv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/cluster-async-tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/cluster-async.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions examples/cluster-clientside-caching-async.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/client_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/clusterclient_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ";
Expand Down
12 changes: 1 addition & 11 deletions tests/ct_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/ct_async_glib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ct_async_libev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ct_async_libuv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
26 changes: 15 additions & 11 deletions tests/ct_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 7 additions & 3 deletions tests/ct_out_of_memory_handling.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down
10 changes: 7 additions & 3 deletions tests/ct_pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down
26 changes: 15 additions & 11 deletions tests/ct_specific_nodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b432508

Please sign in to comment.