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
367246bb
Commit
367246bb
authored
Feb 01, 2019
by
Simon Giesecke
Committed by
Simon Giesecke
Feb 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: test_monitor is not using a test framework
Solution: migrate to unity
parent
478e4244
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
41 deletions
+55
-41
Makefile.am
Makefile.am
+2
-1
test_monitor.cpp
tests/test_monitor.cpp
+53
-40
No files found.
Makefile.am
View file @
367246bb
...
...
@@ -541,7 +541,8 @@ tests_test_srcfd_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_srcfd_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_monitor_SOURCES
=
tests/test_monitor.cpp
tests_test_monitor_LDADD
=
src/libzmq.la
tests_test_monitor_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_monitor_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_router_mandatory_SOURCES
=
tests/test_router_mandatory.cpp tests/testutil_unity.hpp
tests_test_router_mandatory_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
...
...
tests/test_monitor.cpp
View file @
367246bb
...
...
@@ -30,56 +30,61 @@
#include "testutil.hpp"
#include "testutil_security.hpp"
int
main
(
void
)
#include "testutil_unity.hpp"
void
setUp
()
{
setup_test_environment
();
setup_test_context
();
}
size_t
len
=
MAX_SOCKET_STRING
;
char
my_endpoint
[
MAX_SOCKET_STRING
];
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
void
tearDown
()
{
teardown_test_context
();
}
// We'll monitor these two sockets
void
*
client
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
client
);
void
*
server
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
server
);
void
test_monitor_invalid_protocol_fails
()
{
void
*
client
=
test_context_socket
(
ZMQ_DEALER
);
// Socket monitoring only works over inproc://
int
rc
=
zmq_socket_monitor
(
client
,
"tcp://127.0.0.1:*"
,
0
);
assert
(
rc
==
-
1
);
assert
(
zmq_errno
()
==
EPROTONOSUPPORT
);
TEST_ASSERT_FAILURE_ERRNO
(
EPROTONOSUPPORT
,
zmq_socket_monitor
(
client
,
"tcp://127.0.0.1:*"
,
0
));
}
void
test_monitor_basic
()
{
char
my_endpoint
[
MAX_SOCKET_STRING
];
// We'll monitor these two sockets
void
*
client
=
test_context_socket
(
ZMQ_DEALER
);
void
*
server
=
test_context_socket
(
ZMQ_DEALER
);
// Monitor all events on client and server sockets
rc
=
zmq_socket_monitor
(
client
,
"inproc://monitor-client"
,
ZMQ_EVENT_ALL
);
assert
(
rc
==
0
);
rc
=
zmq_socket_monitor
(
server
,
"inproc://monitor-server"
,
ZMQ_EVENT_ALL
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_socket_monitor
(
client
,
"inproc://monitor-client"
,
ZMQ_EVENT_ALL
)
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_socket_monitor
(
server
,
"inproc://monitor-server"
,
ZMQ_EVENT_ALL
)
);
// Create two sockets for collecting monitor events
void
*
client_mon
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
assert
(
client_mon
);
void
*
server_mon
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
assert
(
server_mon
);
void
*
client_mon
=
test_context_socket
(
ZMQ_PAIR
);
void
*
server_mon
=
test_context_socket
(
ZMQ_PAIR
);
// Connect these to the inproc endpoints so they'll get events
rc
=
zmq_connect
(
client_mon
,
"inproc://monitor-client"
);
assert
(
rc
==
0
);
rc
=
zmq_connect
(
server_mon
,
"inproc://monitor-server"
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
client_mon
,
"inproc://monitor-client"
)
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
server_mon
,
"inproc://monitor-server"
)
);
// Now do a basic ping test
rc
=
zmq_bind
(
server
,
"tcp://127.0.0.1:*"
);
assert
(
rc
==
0
);
rc
=
zmq_getsockopt
(
server
,
ZMQ_LAST_ENDPOINT
,
my_endpoint
,
&
len
);
assert
(
rc
==
0
);
rc
=
zmq_connect
(
client
,
my_endpoint
);
assert
(
rc
==
0
);
bind_loopback_ipv4
(
server
,
my_endpoint
,
sizeof
my_endpoint
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
client
,
my_endpoint
));
bounce
(
server
,
client
);
// Close client and server
close_zero_linger
(
client
);
close_zero_linger
(
server
);
// TODO why does this use zero_linger?
test_context_socket_close_zero_linger
(
client
);
test_context_socket_close_zero_linger
(
server
);
// Now collect and check events from both sockets
int
event
=
get_monitor_event
(
client_mon
,
NULL
,
NULL
);
...
...
@@ -96,17 +101,25 @@ int main (void)
event
=
get_monitor_event
(
server_mon
,
NULL
,
NULL
);
// Sometimes the server sees the client closing before it gets closed.
if
(
event
!=
ZMQ_EVENT_DISCONNECTED
)
{
assert
(
event
==
ZMQ_EVENT_CLOSED
);
TEST_ASSERT_EQUAL_INT
(
ZMQ_EVENT_CLOSED
,
event
);
event
=
get_monitor_event
(
server_mon
,
NULL
,
NULL
);
}
if
(
event
!=
ZMQ_EVENT_DISCONNECTED
)
{
assert
(
event
==
ZMQ_EVENT_MONITOR_STOPPED
);
TEST_ASSERT_EQUAL_INT
(
ZMQ_EVENT_MONITOR_STOPPED
,
event
);
}
// Close down the sockets
close_zero_linger
(
client_mon
);
close_zero_linger
(
server_mon
);
zmq_ctx_term
(
ctx
);
// TODO why does this use zero_linger?
test_context_socket_close_zero_linger
(
client_mon
);
test_context_socket_close_zero_linger
(
server_mon
);
}
int
main
()
{
setup_test_environment
();
return
0
;
UNITY_BEGIN
();
RUN_TEST
(
test_monitor_invalid_protocol_fails
);
RUN_TEST
(
test_monitor_basic
);
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