From 2a9dd21699a2d5b8fac31151480e6332e333aefd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= Date: Mon, 30 Sep 2024 11:21:53 +0200 Subject: [PATCH] Update async tests and example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Björn Svensson --- examples/Makefile | 6 ++++-- tests/clusterclient_async.c | 14 +++++++------- tests/clusterclient_reconnect_async.c | 5 +++-- tests/ct_async_glib.c | 4 +--- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/examples/Makefile b/examples/Makefile index de02631..6a5f06d 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -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) @@ -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 diff --git a/tests/clusterclient_async.c b/tests/clusterclient_async.c index c3b920a..f144900 100644 --- a/tests/clusterclient_async.c +++ b/tests/clusterclient_async.c @@ -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); } } @@ -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 */ @@ -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); } } @@ -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); diff --git a/tests/clusterclient_reconnect_async.c b/tests/clusterclient_reconnect_async.c index 90ab2ae..1fa6841 100644 --- a/tests/clusterclient_reconnect_async.c +++ b/tests/clusterclient_reconnect_async.c @@ -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) { @@ -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); diff --git a/tests/ct_async_glib.c b/tests/ct_async_glib.c index 9d49121..8aafca4 100644 --- a/tests/ct_async_glib.c +++ b/tests/ct_async_glib.c @@ -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);