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
631de945
Commit
631de945
authored
Mar 14, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: test_router_hangover not yet using unity
Solution: migrate to unity
parent
59157f0e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
58 deletions
+53
-58
test_router_handover.cpp
tests/test_router_handover.cpp
+53
-58
No files found.
tests/test_router_handover.cpp
View file @
631de945
...
@@ -29,89 +29,84 @@
...
@@ -29,89 +29,84 @@
#include "testutil.hpp"
#include "testutil.hpp"
int
main
(
void
)
#include "testutil_unity.hpp"
#include <unity.h>
void
setUp
()
{
setup_test_context
();
}
void
tearDown
()
{
teardown_test_context
();
}
void
test_x
()
{
{
setup_test_environment
();
size_t
len
=
MAX_SOCKET_STRING
;
size_t
len
=
MAX_SOCKET_STRING
;
char
my_endpoint
[
MAX_SOCKET_STRING
];
char
my_endpoint
[
MAX_SOCKET_STRING
];
void
*
ctx
=
zmq_ctx_new
();
void
*
router
=
test_context_socket
(
ZMQ_ROUTER
);
assert
(
ctx
);
void
*
router
=
zmq_socket
(
ctx
,
ZMQ_ROUTER
);
assert
(
router
);
int
rc
=
zmq_bind
(
router
,
"tcp://127.0.0.1:*"
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
router
,
"tcp://127.0.0.1:*"
));
assert
(
rc
==
0
);
rc
=
zmq_getsockopt
(
router
,
ZMQ_LAST_ENDPOINT
,
my_endpoint
,
&
len
);
TEST_ASSERT_SUCCESS_ERRNO
(
assert
(
rc
==
0
);
zmq_getsockopt
(
router
,
ZMQ_LAST_ENDPOINT
,
my_endpoint
,
&
len
)
);
// Enable the handover flag
// Enable the handover flag
int
handover
=
1
;
int
handover
=
1
;
rc
=
zmq_setsockopt
(
router
,
ZMQ_ROUTER_HANDOVER
,
&
handover
,
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
router
,
ZMQ_ROUTER_HANDOVER
,
sizeof
(
handover
));
&
handover
,
sizeof
(
handover
)));
assert
(
rc
==
0
);
// Create dealer called "X" and connect it to our router
// Create dealer called "X" and connect it to our router
void
*
dealer_one
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
void
*
dealer_one
=
test_context_socket
(
ZMQ_DEALER
);
assert
(
dealer_one
);
TEST_ASSERT_SUCCESS_ERRNO
(
rc
=
zmq_setsockopt
(
dealer_one
,
ZMQ_ROUTING_ID
,
"X"
,
1
);
zmq_setsockopt
(
dealer_one
,
ZMQ_ROUTING_ID
,
"X"
,
1
));
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
dealer_one
,
my_endpoint
));
rc
=
zmq_connect
(
dealer_one
,
my_endpoint
);
assert
(
rc
==
0
);
// Get message from dealer to know when connection is ready
// Get message from dealer to know when connection is ready
char
buffer
[
255
];
char
buffer
[
255
];
rc
=
zmq_send
(
dealer_one
,
"Hello"
,
5
,
0
);
send_string_expect_success
(
dealer_one
,
"Hello"
,
0
);
assert
(
rc
==
5
);
rc
=
zmq_recv
(
router
,
buffer
,
255
,
0
);
recv_string_expect_success
(
router
,
"X"
,
0
);
assert
(
rc
==
1
);
recv_string_expect_success
(
router
,
"Hello"
,
0
);
assert
(
buffer
[
0
]
==
'X'
);
rc
=
zmq_recv
(
router
,
buffer
,
255
,
0
);
assert
(
rc
==
5
);
// Now create a second dealer that uses the same routing id
// Now create a second dealer that uses the same routing id
void
*
dealer_two
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
void
*
dealer_two
=
test_context_socket
(
ZMQ_DEALER
);
assert
(
dealer_two
);
TEST_ASSERT_SUCCESS_ERRNO
(
rc
=
zmq_setsockopt
(
dealer_two
,
ZMQ_ROUTING_ID
,
"X"
,
1
);
zmq_setsockopt
(
dealer_two
,
ZMQ_ROUTING_ID
,
"X"
,
1
));
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
dealer_two
,
my_endpoint
));
rc
=
zmq_connect
(
dealer_two
,
my_endpoint
);
assert
(
rc
==
0
);
// Get message from dealer to know when connection is ready
// Get message from dealer to know when connection is ready
rc
=
zmq_send
(
dealer_two
,
"Hello"
,
5
,
0
);
send_string_expect_success
(
dealer_two
,
"Hello"
,
0
);
assert
(
rc
==
5
);
rc
=
zmq_recv
(
router
,
buffer
,
255
,
0
);
recv_string_expect_success
(
router
,
"X"
,
0
);
assert
(
rc
==
1
);
recv_string_expect_success
(
router
,
"Hello"
,
0
);
assert
(
buffer
[
0
]
==
'X'
);
rc
=
zmq_recv
(
router
,
buffer
,
255
,
0
);
assert
(
rc
==
5
);
// Send a message to 'X' routing id. This should be delivered
// Send a message to 'X' routing id. This should be delivered
// to the second dealer, instead of the first beccause of the handover.
// to the second dealer, instead of the first beccause of the handover.
rc
=
zmq_send
(
router
,
"X"
,
1
,
ZMQ_SNDMORE
);
send_string_expect_success
(
router
,
"X"
,
ZMQ_SNDMORE
);
assert
(
rc
==
1
);
send_string_expect_success
(
router
,
"Hello"
,
0
);
rc
=
zmq_send
(
router
,
"Hello"
,
5
,
0
);
assert
(
rc
==
5
);
// Ensure that the first dealer doesn't receive the message
// Ensure that the first dealer doesn't receive the message
// but the second one does
// but the second one does
rc
=
zmq_recv
(
dealer_one
,
buffer
,
255
,
ZMQ_NOBLOCK
);
int
rc
=
zmq_recv
(
dealer_one
,
buffer
,
255
,
ZMQ_NOBLOCK
);
assert
(
rc
==
-
1
);
TEST_ASSERT_EQUAL_INT
(
-
1
,
rc
);
TEST_ASSERT_EQUAL_INT
(
EAGAIN
,
errno
);
rc
=
zmq_recv
(
dealer_two
,
buffer
,
255
,
0
);
assert
(
rc
==
5
);
rc
=
zmq_close
(
router
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
dealer_one
);
recv_string_expect_success
(
dealer_two
,
"Hello"
,
0
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
dealer_two
);
test_context_socket_close
(
router
);
assert
(
rc
==
0
);
test_context_socket_close
(
dealer_one
);
test_context_socket_close
(
dealer_two
);
}
rc
=
zmq_ctx_term
(
ctx
);
int
main
(
void
)
assert
(
rc
==
0
);
{
setup_test_environment
();
return
0
;
UNITY_BEGIN
();
RUN_TEST
(
test_x
);
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