diff options
-rw-r--r-- | tests/Makefile.am | 4 | ||||
-rw-r--r-- | tests/test_linger.cpp | 62 |
2 files changed, 65 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index a63c1de..6a28e65 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -12,7 +12,8 @@ noinst_PROGRAMS = test_pair_inproc \ test_sub_forward \ test_invalid_rep \ test_msg_flags \ - test_reconnect + test_reconnect \ + test_linger if !ON_MINGW noinst_PROGRAMS += test_shutdown_stress \ @@ -31,6 +32,7 @@ test_sub_forward_SOURCES = test_sub_forward.cpp test_invalid_rep_SOURCES = test_invalid_rep.cpp test_msg_flags_SOURCES = test_msg_flags.cpp test_reconnect_SOURCES = test_reconnect.cpp +test_linger_SOURCES = test_linger.cpp if !ON_MINGW test_shutdown_stress_SOURCES = test_shutdown_stress.cpp diff --git a/tests/test_linger.cpp b/tests/test_linger.cpp new file mode 100644 index 0000000..942c309 --- /dev/null +++ b/tests/test_linger.cpp @@ -0,0 +1,62 @@ +/* + Copyright (c) 2012 250bpm s.r.o. + Copyright (c) 2012 Other contributors as noted in the AUTHORS file + + This file is part of Crossroads project. + + Crossroads is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Crossroads is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "../include/xs.h" +#include "../include/xs_utils.h" +#include <assert.h> +#include <stdio.h> + +int main (int argc, char *argv []) +{ + fprintf (stderr, "test_invalid_rep running...\n"); + + // Create REQ/XREP wiring. + void *ctx = xs_init (1); + assert (ctx); + void *s = xs_socket (ctx, XS_PUSH); + assert (s); + + // Set linger to 0.1 second. + int linger = 100; + int rc = xs_setsockopt (s, XS_LINGER, &linger, sizeof (int)); + + // Connect to non-existent endpoing. + assert (rc == 0); + rc = xs_connect (s, "ipc:///tmp/this-file-does-not-exist"); + assert (rc == 0); + + // Send a message. + rc = xs_send (s, "r", 1, 0); + assert (rc == 1); + + // Close the socket. + rc = xs_close (s); + assert (rc == 0); + + // Terminate the context. This should take 0.1 second. + void *watch = xs_stopwatch_start (); + rc = xs_term (ctx); + assert (rc == 0); + int ms = (int) xs_stopwatch_stop (watch) / 1000; + assert (ms > 50 && ms < 150); + + return 0; +} + |