Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
5d32828b
Commit
5d32828b
authored
Mar 15, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: test_reconnect_ivl not using unity
Solution: migrate to unity, and reduce code duplication
parent
1e217ac0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
79 deletions
+52
-79
Makefile.am
Makefile.am
+2
-1
test_reconnect_ivl.cpp
tests/test_reconnect_ivl.cpp
+50
-78
No files found.
Makefile.am
View file @
5d32828b
...
...
@@ -669,7 +669,8 @@ tests_test_socket_null_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_socket_null_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_reconnect_ivl_SOURCES
=
tests/test_reconnect_ivl.cpp
tests_test_reconnect_ivl_LDADD
=
src/libzmq.la
tests_test_reconnect_ivl_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_reconnect_ivl_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
if
HAVE_CURVE
...
...
tests/test_reconnect_ivl.cpp
View file @
5d32828b
...
...
@@ -28,52 +28,54 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
#include <unity.h>
#ifndef ZMQ_HAVE_WINDOWS
void
test_reconnect_ivl_ipc
(
void
)
void
setUp
()
{
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
setup_test_context
();
}
void
*
sb
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
assert
(
sb
);
int
rc
=
zmq_bind
(
sb
,
"ipc:///tmp/test_reconnect_ivl"
);
assert
(
rc
==
0
);
void
tearDown
()
{
teardown_test_context
(
);
}
void
*
sc
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
assert
(
sc
);
void
test_reconnect_ivl_against_pair_socket
(
const
char
*
my_endpoint
,
void
*
sb
)
{
void
*
sc
=
test_context_socket
(
ZMQ_PAIR
);
int
interval
=
-
1
;
rc
=
zmq_setsockopt
(
sc
,
ZMQ_RECONNECT_IVL
,
&
interval
,
sizeof
(
int
));
assert
(
rc
==
0
);
rc
=
zmq_connect
(
sc
,
"ipc:///tmp/test_reconnect_ivl"
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sc
,
ZMQ_RECONNECT_IVL
,
&
interval
,
sizeof
(
int
)));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
sc
,
my_endpoint
));
bounce
(
sb
,
sc
);
rc
=
zmq_unbind
(
sb
,
"ipc:///tmp/test_reconnect_ivl"
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_unbind
(
sb
,
my_endpoint
));
expect_bounce_fail
(
sb
,
sc
);
rc
=
zmq_bind
(
sb
,
"ipc:///tmp/test_reconnect_ivl"
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
sb
,
my_endpoint
));
expect_bounce_fail
(
sb
,
sc
);
rc
=
zmq_connect
(
sc
,
"ipc:///tmp/test_reconnect_ivl"
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
sc
,
my_endpoint
));
bounce
(
sb
,
sc
);
rc
=
zmq
_close
(
sc
);
assert
(
rc
==
0
);
test_context_socket
_close
(
sc
);
}
rc
=
zmq_close
(
sb
);
assert
(
rc
==
0
);
#ifndef ZMQ_HAVE_WINDOWS
void
test_reconnect_ivl_ipc
(
void
)
{
const
char
*
ipc_endpoint
=
"ipc:///tmp/test_reconnect_ivl"
;
void
*
sb
=
test_context_socket
(
ZMQ_PAIR
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
sb
,
ipc_endpoint
));
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
test_reconnect_ivl_against_pair_socket
(
ipc_endpoint
,
sb
);
test_context_socket_close
(
sb
);
}
#endif
...
...
@@ -81,69 +83,39 @@ void test_reconnect_ivl_tcp (const char *address)
{
size_t
len
=
MAX_SOCKET_STRING
;
char
my_endpoint
[
MAX_SOCKET_STRING
];
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
if
(
streq
(
address
,
"tcp://[::1]:*"
))
{
if
(
is_ipv6_available
())
{
zmq_ctx_set
(
ctx
,
ZMQ_IPV6
,
1
);
}
else
{
zmq_ctx_term
(
ctx
);
return
;
}
}
void
*
sb
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
assert
(
sb
);
int
rc
=
zmq_bind
(
sb
,
address
);
assert
(
rc
==
0
);
rc
=
zmq_getsockopt
(
sb
,
ZMQ_LAST_ENDPOINT
,
my_endpoint
,
&
len
);
assert
(
rc
==
0
);
void
*
sc
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
assert
(
sc
);
int
interval
=
-
1
;
rc
=
zmq_setsockopt
(
sc
,
ZMQ_RECONNECT_IVL
,
&
interval
,
sizeof
(
int
));
assert
(
rc
==
0
);
rc
=
zmq_connect
(
sc
,
my_endpoint
);
assert
(
rc
==
0
);
bounce
(
sb
,
sc
);
rc
=
zmq_unbind
(
sb
,
my_endpoint
);
assert
(
rc
==
0
);
void
*
sb
=
test_context_socket
(
ZMQ_PAIR
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
sb
,
address
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
sb
,
ZMQ_LAST_ENDPOINT
,
my_endpoint
,
&
len
));
expect_bounce_fail
(
sb
,
sc
);
rc
=
zmq_bind
(
sb
,
my_endpoint
);
assert
(
rc
==
0
);
expect_bounce_fail
(
sb
,
sc
);
rc
=
zmq_connect
(
sc
,
my_endpoint
);
assert
(
rc
==
0
);
bounce
(
sb
,
sc
);
rc
=
zmq_close
(
sc
);
assert
(
rc
==
0
);
test_reconnect_ivl_against_pair_socket
(
my_endpoint
,
sb
);
test_context_socket_close
(
sb
);
}
rc
=
zmq_close
(
sb
);
assert
(
rc
==
0
);
void
test_reconnect_ivl_tcp_ipv4
()
{
test_reconnect_ivl_tcp
(
"tcp://127.0.0.1:*"
);
}
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
void
test_reconnect_ivl_tcp_ipv6
()
{
if
(
is_ipv6_available
())
{
zmq_ctx_set
(
get_test_context
(),
ZMQ_IPV6
,
1
);
test_reconnect_ivl_tcp
(
"tcp://[::1]:*"
);
}
}
int
main
(
void
)
{
setup_test_environment
();
UNITY_BEGIN
();
#ifndef ZMQ_HAVE_WINDOWS
test_reconnect_ivl_ipc
(
);
RUN_TEST
(
test_reconnect_ivl_ipc
);
#endif
test_reconnect_ivl_tcp
(
"tcp://127.0.0.1:*"
);
test_reconnect_ivl_tcp
(
"tcp://[::1]:*"
);
RUN_TEST
(
test_reconnect_ivl_tcp_ipv4
);
RUN_TEST
(
test_reconnect_ivl_tcp_ipv6
);
return
0
;
return
UNITY_END
()
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment