diff options
author | Garrett D'Amore <garrett@damore.org> | 2017-10-14 02:15:14 -0700 |
---|---|---|
committer | Garrett D'Amore <garrett@damore.org> | 2017-10-14 02:15:14 -0700 |
commit | 53294f08bb40513a9cbf6d35806bf3e3698d2718 (patch) | |
tree | f2f8c0b1ec0140a3bda0df08d5e8e61fefc355eb | |
parent | 83f3b270a573fca4dd82edb38c1d8a49334c1039 (diff) | |
download | nanomsg-appveyor2.tar.gz |
Rebinding is problematic, fix a ws_async_shutdown timeout.appveyor2
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/ws_async_shutdown.c | 44 |
2 files changed, 32 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5274442..c811a01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -409,7 +409,7 @@ if (NN_TESTS) add_libnanomsg_test (cmsg 5) add_libnanomsg_test (bug328 5) add_libnanomsg_test (bug777 5) - add_libnanomsg_test (ws_async_shutdown 5) + add_libnanomsg_test (ws_async_shutdown 30) add_libnanomsg_test (reqttl 10) add_libnanomsg_test (surveyttl 10) diff --git a/tests/ws_async_shutdown.c b/tests/ws_async_shutdown.c index cac4b3f..bf2a3ec 100644 --- a/tests/ws_async_shutdown.c +++ b/tests/ws_async_shutdown.c @@ -1,6 +1,7 @@ /* Copyright (c) 2012 Martin Sustrik All rights reserved. Copyright (c) 2015-2016 Jack R. Dunaway. All rights reserved. + Copyright 2017 Garrett D'Amore <garrett@damore.org> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -31,22 +32,37 @@ static char socket_address [128]; /* Test condition of closing sockets that are blocking in another thread. */ -#define TEST_LOOPS 10 +#define TEST_LOOPS 5 #define TEST_THREADS 10 -static void routine (NN_UNUSED void *arg) +static void sender (void *arg) { int s; int rc; - char msg[1]; + + s = *(int *)arg; + for (;;) { + rc = nn_send (s, "hello", 5, 0); + if (rc < 0) { + break; + } + nn_sleep(10); + } +} + +static void routine (void *arg) +{ + int s; + int rc; + char msg[10]; nn_assert (arg); s = *(int *)arg; - while (1) { + for (;;) { rc = nn_recv (s, &msg, sizeof(msg), 0); - if (rc == 0) { + if (rc >= 0) { continue; } @@ -72,16 +88,19 @@ int main (int argc, const char *argv[]) int sndtimeo = 0; int sockets [TEST_THREADS]; struct nn_thread threads [TEST_THREADS]; + struct nn_thread send_thr; test_addr_from (socket_address, "ws", "127.0.0.1", get_test_port (argc, argv)); + sb = test_socket (AF_SP, NN_PUB); + test_bind (sb, socket_address); + test_setsockopt (sb, NN_SOL_SOCKET, NN_SNDTIMEO, + &sndtimeo, sizeof (sndtimeo)); + nn_thread_init (&send_thr, sender, &sb); + for (i = 0; i != TEST_LOOPS; ++i) { - sb = test_socket (AF_SP, NN_PUB); - test_bind (sb, socket_address); - test_setsockopt (sb, NN_SOL_SOCKET, NN_SNDTIMEO, - &sndtimeo, sizeof (sndtimeo)); for (j = 0; j < TEST_THREADS; j++){ s = test_socket (AF_SP, NN_SUB); @@ -96,15 +115,14 @@ int main (int argc, const char *argv[]) /* Allow all threads a bit of time to connect. */ nn_sleep (100); - test_send (sb, ""); - for (j = 0; j < TEST_THREADS; j++) { test_close (sockets [j]); nn_thread_term (&threads [j]); } - - test_close (sb); } + test_close (sb); + nn_thread_term (&send_thr); + return 0; } |