Commit 8f90f579 authored by Simon Giesecke's avatar Simon Giesecke

Problem: no assertions for local and remote addresses in monitor tests

Solution: added such assertions and extended test utilities
parent f884fa72
...@@ -117,7 +117,7 @@ void test_monitor_basic () ...@@ -117,7 +117,7 @@ void test_monitor_basic ()
#ifdef ZMQ_BUILD_DRAFT_API #ifdef ZMQ_BUILD_DRAFT_API
void test_monitor_versioned_basic () void test_monitor_versioned_basic ()
{ {
char my_endpoint[MAX_SOCKET_STRING]; char server_endpoint[MAX_SOCKET_STRING];
// We'll monitor these two sockets // We'll monitor these two sockets
void *client = test_context_socket (ZMQ_DEALER); void *client = test_context_socket (ZMQ_DEALER);
...@@ -140,9 +140,9 @@ void test_monitor_versioned_basic () ...@@ -140,9 +140,9 @@ void test_monitor_versioned_basic ()
zmq_connect (server_mon, "inproc://monitor-server")); zmq_connect (server_mon, "inproc://monitor-server"));
// Now do a basic ping test // 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); bounce (server, client);
// Close client and server // Close client and server
...@@ -150,18 +150,36 @@ void test_monitor_versioned_basic () ...@@ -150,18 +150,36 @@ void test_monitor_versioned_basic ()
test_context_socket_close_zero_linger (client); test_context_socket_close_zero_linger (client);
test_context_socket_close_zero_linger (server); 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 // Now collect and check events from both sockets
int64_t event = get_monitor_event_v2 (client_mon, NULL, NULL, NULL); int64_t event = get_monitor_event_v2 (
if (event == ZMQ_EVENT_CONNECT_DELAYED) client_mon, NULL, &client_local_address, &client_remote_address);
event = get_monitor_event_v2 (client_mon, NULL, NULL, NULL); if (event == ZMQ_EVENT_CONNECT_DELAYED) {
assert (event == ZMQ_EVENT_CONNECTED); free (client_local_address);
expect_monitor_event_v2 (client_mon, ZMQ_EVENT_HANDSHAKE_SUCCEEDED); 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); expect_monitor_event_v2 (client_mon, ZMQ_EVENT_MONITOR_STOPPED);
// This is the flow of server events // This is the flow of server events
expect_monitor_event_v2 (server_mon, ZMQ_EVENT_LISTENING); 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_ACCEPTED,
expect_monitor_event_v2 (server_mon, ZMQ_EVENT_HANDSHAKE_SUCCEEDED); 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); event = get_monitor_event_v2 (server_mon, NULL, NULL, NULL);
// Sometimes the server sees the client closing before it gets closed. // Sometimes the server sees the client closing before it gets closed.
if (event != ZMQ_EVENT_DISCONNECTED) { if (event != ZMQ_EVENT_DISCONNECTED) {
...@@ -171,6 +189,8 @@ void test_monitor_versioned_basic () ...@@ -171,6 +189,8 @@ void test_monitor_versioned_basic ()
if (event != ZMQ_EVENT_DISCONNECTED) { if (event != ZMQ_EVENT_DISCONNECTED) {
TEST_ASSERT_EQUAL_INT (ZMQ_EVENT_MONITOR_STOPPED, event); TEST_ASSERT_EQUAL_INT (ZMQ_EVENT_MONITOR_STOPPED, event);
} }
free (client_local_address);
free (client_remote_address);
// Close down the sockets // Close down the sockets
// TODO why does this use zero_linger? // TODO why does this use zero_linger?
......
...@@ -297,16 +297,37 @@ int64_t get_monitor_event_v2 (void *monitor_, ...@@ -297,16 +297,37 @@ int64_t get_monitor_event_v2 (void *monitor_,
remote_address_, -1); remote_address_, -1);
} }
void expect_monitor_event_v2 (void *monitor_, int64_t expected_event_) void expect_monitor_event_v2 (void *monitor_,
int64_t expected_event_,
const char *expected_local_address_ = NULL,
const char *expected_remote_address_ = NULL)
{ {
int64_t event = get_monitor_event_v2 (monitor_, NULL, NULL, NULL); char *local_address = NULL;
char *remote_address = NULL;
int64_t event = get_monitor_event_v2 (
monitor_, NULL, expected_local_address_ ? &local_address : NULL,
expected_remote_address_ ? &remote_address : NULL);
bool failed = false;
if (event != expected_event_) { if (event != expected_event_) {
fprintf (stderr, fprintf (stderr,
"Expected monitor event %" PRIx64 " but received %" PRIx64 "Expected monitor event %" PRIx64 ", but received %" PRIx64
"\n", "\n",
expected_event_, event); expected_event_, event);
assert (event == expected_event_); failed = true;
}
if (expected_local_address_
&& 0 != strcmp (local_address, expected_local_address_)) {
fprintf (stderr, "Expected local address %s, but received %s\n",
expected_local_address_, local_address);
}
if (expected_remote_address_
&& 0 != strcmp (remote_address, expected_remote_address_)) {
fprintf (stderr, "Expected remote address %s, but received %s\n",
expected_remote_address_, remote_address);
} }
free (local_address);
free (remote_address);
assert (!failed);
} }
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment