From 3ede6c4b4c60dde55086a9b0301127630f185846 Mon Sep 17 00:00:00 2001 From: Dmitry Simonenko Date: Wed, 7 Dec 2016 18:17:00 +0300 Subject: [PATCH] machinarium: add getaddrinfo cancelation test --- .gitignore | 1 + tests/makefile | 3 ++ tests/test_cancel_getaddrinfo.c | 52 +++++++++++++++++++++++++++++++++ tests/test_getaddrinfo.c | 1 - 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests/test_cancel_getaddrinfo.c diff --git a/.gitignore b/.gitignore index 97c8d6e5..a4c7964d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ tests/test_client_server tests/test_client_server_ra tests/test_cancel_sleep tests/test_cancel_sleep_2 +tests/test_cancel_getaddrinfo tests/test_cancel_connect tests/test_cancel_connect_2 tests/test_cancel_read diff --git a/tests/makefile b/tests/makefile index bb415249..a7e76f8c 100644 --- a/tests/makefile +++ b/tests/makefile @@ -14,6 +14,7 @@ TESTS = test_new \ test_client_server_ra \ test_cancel_sleep \ test_cancel_sleep_2 \ + test_cancel_getaddrinfo \ test_cancel_connect \ test_cancel_connect_2 \ test_cancel_read \ @@ -40,6 +41,8 @@ test_cancel_sleep: $(CC) $(CFLAGS) test_cancel_sleep.c $(LFLAGS) -o test_cancel_sleep test_cancel_sleep_2: $(CC) $(CFLAGS) test_cancel_sleep_2.c $(LFLAGS) -o test_cancel_sleep_2 +test_cancel_getaddrinfo: + $(CC) $(CFLAGS) test_cancel_getaddrinfo.c $(LFLAGS) -o test_cancel_getaddrinfo test_cancel_connect: $(CC) $(CFLAGS) test_cancel_connect.c $(LFLAGS) -o test_cancel_connect test_cancel_connect_2: diff --git a/tests/test_cancel_getaddrinfo.c b/tests/test_cancel_getaddrinfo.c new file mode 100644 index 00000000..b982bf52 --- /dev/null +++ b/tests/test_cancel_getaddrinfo.c @@ -0,0 +1,52 @@ + +/* + * machinarium. + * + * Cooperative multitasking engine. +*/ + +#include +#include + +static void +test_gai(void *arg) +{ + printf("child started\n"); + mm_t env = arg; + mm_io_t io = mm_io_new(env); + struct addrinfo *res = NULL; + int rc = mm_getaddrinfo(io, "abracadabra", "http", NULL, &res, 0); + assert(rc < 0); + mm_close(io); + assert(res == NULL); + if (mm_is_cancel(env)) + printf("child marked as cancel\n"); + printf("child done\n"); +} + +static void +test_waiter(void *arg) +{ + mm_t env = arg; + + printf("waiter started\n"); + + int id = mm_create(env, test_gai, env); + mm_sleep(env, 0); + mm_cancel(env, id); + mm_wait(env, id); + + printf("waiter ended \n"); + mm_stop(env); +} + +int +main(int argc, char *argv[]) +{ + mm_t env = mm_new(); + mm_create(env, test_waiter, env); + mm_start(env); + printf("shutting down\n"); + mm_free(env); + return 0; +} diff --git a/tests/test_getaddrinfo.c b/tests/test_getaddrinfo.c index 93831fce..1871ccd3 100644 --- a/tests/test_getaddrinfo.c +++ b/tests/test_getaddrinfo.c @@ -13,7 +13,6 @@ fiber(void *arg) { mm_t env = arg; mm_io_t io = mm_io_new(env); - struct addrinfo *res = NULL; int rc = mm_getaddrinfo(io, "localhost", "http", NULL, &res, 0); if (rc < 0) {