diff options
author | Martin Sustrik <sustrik@250bpm.com> | 2012-02-16 10:05:37 +0900 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2012-02-16 10:05:37 +0900 |
commit | 4d15d0dcd4772f57f729a69d2c497461820ccb37 (patch) | |
tree | 9fda26df235109e67d9f559c6337666012dbaf37 /tests | |
parent | bdc43541b79f618c5cbcdcf11dcc0dcdd046d682 (diff) |
Test for LINGER added
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'tests')
-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; +} + |