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
309fe2e6
Commit
309fe2e6
authored
6 years ago
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: test_router_mandatory_hwm not yet using unity
Solution: migrate to unity
parent
fd27324e
master
v4.3.2
v4.3.2-win
v4.3.1
v4.3.0
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
54 deletions
+47
-54
Makefile.am
Makefile.am
+2
-1
test_router_mandatory_hwm.cpp
tests/test_router_mandatory_hwm.cpp
+45
-53
No files found.
Makefile.am
View file @
309fe2e6
...
...
@@ -533,7 +533,8 @@ tests_test_router_mandatory_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_router_mandatory_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_router_mandatory_hwm_SOURCES
=
tests/test_router_mandatory_hwm.cpp
tests_test_router_mandatory_hwm_LDADD
=
src/libzmq.la
tests_test_router_mandatory_hwm_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_router_mandatory_hwm_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_router_handover_SOURCES
=
tests/test_router_handover.cpp
tests_test_router_handover_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
...
...
This diff is collapsed.
Click to expand it.
tests/test_router_mandatory_hwm.cpp
View file @
309fe2e6
...
...
@@ -28,6 +28,17 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
void
setUp
()
{
setup_test_context
();
}
void
tearDown
()
{
teardown_test_context
();
}
// DEBUG shouldn't be defined in sources as it will cause a redefined symbol
// error when it is defined in the build configuration. It appears that the
...
...
@@ -36,101 +47,82 @@
//#define DEBUG 0
#define TRACE_ENABLED 0
int
main
(
void
)
void
test_router_mandatory_hwm
(
)
{
int
rc
;
if
(
TRACE_ENABLED
)
fprintf
(
stderr
,
"Staring router mandatory HWM test ...
\n
"
);
setup_test_environment
();
size_t
len
=
MAX_SOCKET_STRING
;
char
my_endpoint
[
MAX_SOCKET_STRING
];
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
void
*
router
=
zmq_socket
(
ctx
,
ZMQ_ROUTER
);
assert
(
router
);
void
*
router
=
test_context_socket
(
ZMQ_ROUTER
);
// Configure router socket to mandatory routing and set HWM and linger
int
mandatory
=
1
;
rc
=
zmq_setsockopt
(
router
,
ZMQ_ROUTER_MANDATORY
,
&
mandatory
,
sizeof
(
mandatory
));
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
router
,
ZMQ_ROUTER_MANDATORY
,
&
mandatory
,
sizeof
(
mandatory
)));
int
sndhwm
=
1
;
rc
=
zmq_setsockopt
(
router
,
ZMQ_SNDHWM
,
&
sndhwm
,
sizeof
(
sndhwm
));
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
router
,
ZMQ_SNDHWM
,
&
sndhwm
,
sizeof
(
sndhwm
))
);
int
linger
=
1
;
rc
=
zmq_setsockopt
(
router
,
ZMQ_LINGER
,
&
linger
,
sizeof
(
linger
));
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
router
,
ZMQ_LINGER
,
&
linger
,
sizeof
(
linger
))
);
rc
=
zmq_bind
(
router
,
"tcp://127.0.0.1:*"
);
assert
(
rc
==
0
);
rc
=
zmq_getsockopt
(
router
,
ZMQ_LAST_ENDPOINT
,
my_endpoint
,
&
len
);
assert
(
rc
==
0
);
bind_loopback_ipv4
(
router
,
my_endpoint
,
sizeof
my_endpoint
);
// Create dealer called "X" and connect it to our router, configure HWM
void
*
dealer
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
assert
(
dealer
);
rc
=
zmq_setsockopt
(
dealer
,
ZMQ_ROUTING_ID
,
"X"
,
1
);
assert
(
rc
==
0
);
void
*
dealer
=
test_context_socket
(
ZMQ_DEALER
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
dealer
,
ZMQ_ROUTING_ID
,
"X"
,
1
));
int
rcvhwm
=
1
;
rc
=
zmq_setsockopt
(
dealer
,
ZMQ_RCVHWM
,
&
rcvhwm
,
sizeof
(
rcvhwm
));
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
dealer
,
ZMQ_RCVHWM
,
&
rcvhwm
,
sizeof
(
rcvhwm
))
);
rc
=
zmq_connect
(
dealer
,
my_endpoint
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
dealer
,
my_endpoint
));
// Get message from dealer to know when connection is ready
char
buffer
[
255
];
rc
=
zmq_send
(
dealer
,
"Hello"
,
5
,
0
);
assert
(
rc
==
5
);
rc
=
zmq_recv
(
router
,
buffer
,
255
,
0
);
assert
(
rc
==
1
);
assert
(
buffer
[
0
]
==
'X'
);
send_string_expect_success
(
dealer
,
"Hello"
,
0
);
recv_string_expect_success
(
router
,
"X"
,
0
);
int
i
;
const
int
buf_size
=
65536
;
char
buf
[
buf_size
];
memset
(
buf
,
0
,
buf_size
);
const
uint8_t
buf
[
buf_size
]
=
{
0
};
// Send first batch of messages
for
(
i
=
0
;
i
<
100000
;
++
i
)
{
if
(
TRACE_ENABLED
)
fprintf
(
stderr
,
"Sending message %d ...
\n
"
,
i
);
rc
=
zmq_send
(
router
,
"X"
,
1
,
ZMQ_DONTWAIT
|
ZMQ_SNDMORE
);
const
int
rc
=
zmq_send
(
router
,
"X"
,
1
,
ZMQ_DONTWAIT
|
ZMQ_SNDMORE
);
if
(
rc
==
-
1
&&
zmq_errno
()
==
EAGAIN
)
break
;
assert
(
rc
==
1
);
rc
=
zmq_send
(
router
,
buf
,
buf_size
,
ZMQ_DONTWAIT
);
assert
(
rc
==
buf_size
);
TEST_ASSERT_EQUAL_INT
(
1
,
rc
);
send_array_expect_success
(
router
,
buf
,
ZMQ_DONTWAIT
);
}
// This should fail after one message but kernel buffering could
// skew results
assert
(
i
<
10
);
TEST_ASSERT_LESS_THAN_INT
(
10
,
i
);
msleep
(
1000
);
// Send second batch of messages
for
(;
i
<
100000
;
++
i
)
{
if
(
TRACE_ENABLED
)
fprintf
(
stderr
,
"Sending message %d (part 2) ...
\n
"
,
i
);
rc
=
zmq_send
(
router
,
"X"
,
1
,
ZMQ_DONTWAIT
|
ZMQ_SNDMORE
);
const
int
rc
=
zmq_send
(
router
,
"X"
,
1
,
ZMQ_DONTWAIT
|
ZMQ_SNDMORE
);
if
(
rc
==
-
1
&&
zmq_errno
()
==
EAGAIN
)
break
;
assert
(
rc
==
1
);
rc
=
zmq_send
(
router
,
buf
,
buf_size
,
ZMQ_DONTWAIT
);
assert
(
rc
==
buf_size
);
TEST_ASSERT_EQUAL_INT
(
1
,
rc
);
send_array_expect_success
(
router
,
buf
,
ZMQ_DONTWAIT
);
}
// This should fail after two messages but kernel buffering could
// skew results
assert
(
i
<
20
);
TEST_ASSERT_LESS_THAN_INT
(
20
,
i
);
if
(
TRACE_ENABLED
)
fprintf
(
stderr
,
"Done sending messages.
\n
"
);
rc
=
zmq_close
(
router
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
dealer
);
assert
(
rc
==
0
);
test_context_socket_close
(
router
);
test_context_socket_close
(
dealer
);
}
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
int
main
()
{
setup_test_environment
();
return
0
;
UNITY_BEGIN
();
RUN_TEST
(
test_router_mandatory_hwm
);
return
UNITY_END
();
}
This diff is collapsed.
Click to expand it.
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