machinarium: add getaddrinfo cancelation test

This commit is contained in:
Dmitry Simonenko 2016-12-07 18:17:00 +03:00
parent af149f8326
commit 3ede6c4b4c
4 changed files with 56 additions and 1 deletions

1
.gitignore vendored
View File

@ -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

View File

@ -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:

View File

@ -0,0 +1,52 @@
/*
* machinarium.
*
* Cooperative multitasking engine.
*/
#include <machinarium.h>
#include <assert.h>
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;
}

View File

@ -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) {