mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-28 19:52:00 +01:00
Problem: no assertions for local and remote addresses in monitor tests
Solution: added such assertions and extended test utilities
This commit is contained in:
@@ -117,7 +117,7 @@ void test_monitor_basic ()
|
||||
#ifdef ZMQ_BUILD_DRAFT_API
|
||||
void test_monitor_versioned_basic ()
|
||||
{
|
||||
char my_endpoint[MAX_SOCKET_STRING];
|
||||
char server_endpoint[MAX_SOCKET_STRING];
|
||||
|
||||
// We'll monitor these two sockets
|
||||
void *client = test_context_socket (ZMQ_DEALER);
|
||||
@@ -140,9 +140,9 @@ void test_monitor_versioned_basic ()
|
||||
zmq_connect (server_mon, "inproc://monitor-server"));
|
||||
|
||||
// Now do a basic ping test
|
||||
bind_loopback_ipv4 (server, my_endpoint, sizeof my_endpoint);
|
||||
bind_loopback_ipv4 (server, server_endpoint, sizeof server_endpoint);
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, my_endpoint));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, server_endpoint));
|
||||
bounce (server, client);
|
||||
|
||||
// Close client and server
|
||||
@@ -150,18 +150,36 @@ void test_monitor_versioned_basic ()
|
||||
test_context_socket_close_zero_linger (client);
|
||||
test_context_socket_close_zero_linger (server);
|
||||
|
||||
char *client_local_address = NULL;
|
||||
char *client_remote_address = NULL;
|
||||
|
||||
// Now collect and check events from both sockets
|
||||
int64_t event = get_monitor_event_v2 (client_mon, NULL, NULL, NULL);
|
||||
if (event == ZMQ_EVENT_CONNECT_DELAYED)
|
||||
event = get_monitor_event_v2 (client_mon, NULL, NULL, NULL);
|
||||
assert (event == ZMQ_EVENT_CONNECTED);
|
||||
expect_monitor_event_v2 (client_mon, ZMQ_EVENT_HANDSHAKE_SUCCEEDED);
|
||||
int64_t event = get_monitor_event_v2 (
|
||||
client_mon, NULL, &client_local_address, &client_remote_address);
|
||||
if (event == ZMQ_EVENT_CONNECT_DELAYED) {
|
||||
free (client_local_address);
|
||||
free (client_remote_address);
|
||||
event = get_monitor_event_v2 (client_mon, NULL, &client_local_address,
|
||||
&client_remote_address);
|
||||
}
|
||||
TEST_ASSERT_EQUAL (ZMQ_EVENT_CONNECTED, event);
|
||||
TEST_ASSERT_EQUAL_STRING (server_endpoint, client_remote_address);
|
||||
static const char prefix[] = "tcp://127.0.0.1:";
|
||||
TEST_ASSERT_EQUAL_STRING_LEN (prefix, client_local_address,
|
||||
strlen (prefix));
|
||||
TEST_ASSERT_NOT_EQUAL (
|
||||
0, strcmp (client_local_address, client_remote_address));
|
||||
|
||||
expect_monitor_event_v2 (client_mon, ZMQ_EVENT_HANDSHAKE_SUCCEEDED,
|
||||
client_local_address, client_remote_address);
|
||||
expect_monitor_event_v2 (client_mon, ZMQ_EVENT_MONITOR_STOPPED);
|
||||
|
||||
// This is the flow of server events
|
||||
expect_monitor_event_v2 (server_mon, ZMQ_EVENT_LISTENING);
|
||||
expect_monitor_event_v2 (server_mon, ZMQ_EVENT_ACCEPTED);
|
||||
expect_monitor_event_v2 (server_mon, ZMQ_EVENT_HANDSHAKE_SUCCEEDED);
|
||||
expect_monitor_event_v2 (server_mon, ZMQ_EVENT_ACCEPTED,
|
||||
client_remote_address, client_local_address);
|
||||
expect_monitor_event_v2 (server_mon, ZMQ_EVENT_HANDSHAKE_SUCCEEDED,
|
||||
client_remote_address, client_local_address);
|
||||
event = get_monitor_event_v2 (server_mon, NULL, NULL, NULL);
|
||||
// Sometimes the server sees the client closing before it gets closed.
|
||||
if (event != ZMQ_EVENT_DISCONNECTED) {
|
||||
@@ -171,6 +189,8 @@ void test_monitor_versioned_basic ()
|
||||
if (event != ZMQ_EVENT_DISCONNECTED) {
|
||||
TEST_ASSERT_EQUAL_INT (ZMQ_EVENT_MONITOR_STOPPED, event);
|
||||
}
|
||||
free (client_local_address);
|
||||
free (client_remote_address);
|
||||
|
||||
// Close down the sockets
|
||||
// TODO why does this use zero_linger?
|
||||
|
||||
Reference in New Issue
Block a user