Skip to content

Commit

Permalink
Update async tests and example
Browse files Browse the repository at this point in the history
Signed-off-by: Björn Svensson <[email protected]>
  • Loading branch information
bjosv committed Sep 30, 2024
1 parent 2ab21ca commit 2a9dd21
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
6 changes: 4 additions & 2 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ example-async-libhv: async-libhv.c $(STLIBNAME)
$(CC) -o $@ $(CFLAGS) $< -lhv $(STLIBNAME)

example-async-libsdevent: async-libsdevent.c $(STLIBNAME)
$(CC) -o $@ $(CFLAGS) $< -lsdevent $(STLIBNAME)
$(CC) -o $@ $(CFLAGS) $< -lsystemd $(STLIBNAME)

example-async-glib: async-glib.c $(STLIBNAME)
$(CC) -o $@ $(CFLAGS) $< $(shell pkg-config --cflags --libs glib-2.0) $(STLIBNAME)
Expand All @@ -69,7 +69,9 @@ example-async-ae:
@false
else
example-async-ae: async-ae.c $(STLIBNAME)
$(CC) -o $@ $(CFLAGS) $(LDFLAGS) -I$(AE_DIR) $< $(AE_DIR)/ae.o $(AE_DIR)/zmalloc.o $(AE_DIR)/../deps/jemalloc/lib/libjemalloc.a -pthread $(STLIBNAME)
$(CC) -o $@ $(CFLAGS) $(LDFLAGS) -I$(AE_DIR) $< $(AE_DIR)/ae.o $(AE_DIR)/zmalloc.o \
$(AE_DIR)/monotonic.o $(AE_DIR)/anet.o $(AE_DIR)/serverassert.o $(AE_DIR)/../deps/jemalloc/lib/libjemalloc.a \
-pthread $(STLIBNAME)
endif

ifndef LIBUV_DIR
Expand Down
14 changes: 7 additions & 7 deletions tests/clusterclient_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ void replyCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) {

if (--num_running == 0) {
/* Schedule a read from stdin and send next command */
event_base_once(acc->adapter, -1, EV_TIMEOUT, sendNextCommand, acc,
NULL);
struct event_base *base = acc->attach_data;
event_base_once(base, -1, EV_TIMEOUT, sendNextCommand, acc, NULL);
}
}

Expand All @@ -125,8 +125,8 @@ void sendNextCommand(evutil_socket_t fd, short kind, void *arg) {
if (strcmp(cmd, "!sleep") == 0) {
ASSERT_MSG(async == 0, "!sleep in !async not supported");
struct timeval timeout = {1, 0};
event_base_once(acc->adapter, -1, EV_TIMEOUT, sendNextCommand,
acc, &timeout);
struct event_base *base = acc->attach_data;
event_base_once(base, -1, EV_TIMEOUT, sendNextCommand, acc, &timeout);
return;
}
if (strcmp(cmd, "!async") == 0) /* Enable async send */
Expand Down Expand Up @@ -172,8 +172,8 @@ void sendNextCommand(evutil_socket_t fd, short kind, void *arg) {
printf("error: %s\n", acc->errstr);

/* Schedule a read from stdin and handle next command. */
event_base_once(acc->adapter, -1, EV_TIMEOUT, sendNextCommand,
acc, NULL);
struct event_base *base = acc->attach_data;
event_base_once(base, -1, EV_TIMEOUT, sendNextCommand, acc, NULL);
}
}

Expand Down Expand Up @@ -275,7 +275,7 @@ int main(int argc, char **argv) {
assert(status == VALKEY_OK);

/* Schedule a read from stdin and send next command */
event_base_once(acc->adapter, -1, EV_TIMEOUT, sendNextCommand, acc, NULL);
event_base_once(base, -1, EV_TIMEOUT, sendNextCommand, acc, NULL);

event_base_dispatch(base);

Expand Down
5 changes: 3 additions & 2 deletions tests/clusterclient_reconnect_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ void replyCallback(valkeyClusterAsyncContext *acc, void *r, void *privdata) {
}

// schedule reading from stdin and sending next command
event_base_once(acc->adapter, -1, EV_TIMEOUT, sendNextCommand, acc, NULL);
struct event_base *base = acc->attach_data;
event_base_once(base, -1, EV_TIMEOUT, sendNextCommand, acc, NULL);
}

void sendNextCommand(evutil_socket_t fd, short kind, void *arg) {
Expand Down Expand Up @@ -109,7 +110,7 @@ int main(int argc, char **argv) {

connectToValkey(acc);
// schedule reading from stdin and sending next command
event_base_once(acc->adapter, -1, EV_TIMEOUT, sendNextCommand, acc, NULL);
event_base_once(base, -1, EV_TIMEOUT, sendNextCommand, acc, NULL);

event_base_dispatch(base);

Expand Down
4 changes: 1 addition & 3 deletions tests/ct_async_glib.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ int main(int argc, char **argv) {
assert(acc);
ASSERT_MSG(acc->err == 0, acc->errstr);

int status;
valkeyClusterGlibAdapter adapter = {.context = context};
status = valkeyClusterGlibAttach(acc, &adapter);
int status = valkeyClusterGlibAttach(acc, context);
assert(status == VALKEY_OK);

valkeyClusterAsyncSetConnectCallback(acc, connectCallback);
Expand Down

0 comments on commit 2a9dd21

Please sign in to comment.