From 4a4c6c27e47219416dc4a784fc0df6f9ba319f28 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 28 Apr 2018 15:29:54 +0100 Subject: [PATCH] Problem: heartbeat tests only cover ROUTER/DEALER Solution: check more socket type to cover other session managers. Increase timeout as the test now takes ~12 seconds. --- tests/CMakeLists.txt | 1 + tests/test_heartbeats.cpp | 50 ++++++++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 11250a55..6ed61060 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -215,6 +215,7 @@ endforeach() if(ZMQ_HAVE_CURVE) set_tests_properties(test_security_curve PROPERTIES TIMEOUT 60) endif() +set_tests_properties(test_heartbeats PROPERTIES TIMEOUT 60) if(WIN32 AND ${POLLER} MATCHES "poll") set_tests_properties(test_many_sockets PROPERTIES TIMEOUT 30) diff --git a/tests/test_heartbeats.cpp b/tests/test_heartbeats.cpp index 7ba46a83..b954dd39 100644 --- a/tests/test_heartbeats.cpp +++ b/tests/test_heartbeats.cpp @@ -72,6 +72,10 @@ static void recv_with_retry (raw_socket fd, char *buffer, int bytes) assert (received <= bytes); if (received == bytes) break; + // ZMQ_REP READY message is shorter, check the actual socket type + if (received >= 3 && buffer[received - 1] == 'P' + && buffer[received - 2] == 'E' && buffer[received - 3] == 'R') + break; } } @@ -135,11 +139,12 @@ static void prep_server_socket (void *ctx, void **server_out, void **mon_out, char *endpoint, - size_t ep_length) + size_t ep_length, + int socket_type) { int rc; // We'll be using this socket in raw mode - void *server = zmq_socket (ctx, ZMQ_ROUTER); + void *server = zmq_socket (ctx, socket_type); assert (server); int value = 0; @@ -180,7 +185,7 @@ static void prep_server_socket (void *ctx, // This checks for a broken TCP connection (or, in this case a stuck one // where the peer never responds to PINGS). There should be an accepted event // then a disconnect event. -static void test_heartbeat_timeout (void) +static void test_heartbeat_timeout (int server_type) { int rc; char my_endpoint[MAX_SOCKET_STRING]; @@ -191,7 +196,7 @@ static void test_heartbeat_timeout (void) void *server, *server_mon; prep_server_socket (ctx, 1, 0, &server, &server_mon, my_endpoint, - MAX_SOCKET_STRING); + MAX_SOCKET_STRING, server_type); struct sockaddr_in ip4addr; raw_socket s; @@ -236,7 +241,7 @@ static void test_heartbeat_timeout (void) // to a server that is not doing any heartbeating. Then we sleep, // if the server disconnects the client, then we know the TTL did // its thing correctly. -static void test_heartbeat_ttl (void) +static void test_heartbeat_ttl (int client_type, int server_type) { int rc, value; char my_endpoint[MAX_SOCKET_STRING]; @@ -247,9 +252,9 @@ static void test_heartbeat_ttl (void) void *server, *server_mon, *client; prep_server_socket (ctx, 0, 0, &server, &server_mon, my_endpoint, - MAX_SOCKET_STRING); + MAX_SOCKET_STRING, server_type); - client = zmq_socket (ctx, ZMQ_DEALER); + client = zmq_socket (ctx, client_type); assert (client != NULL); // Set the heartbeat TTL to 0.1 seconds @@ -292,7 +297,8 @@ static void test_heartbeat_ttl (void) // This checks for normal operation - that is pings and pongs being // exchanged normally. There should be an accepted event on the server, // and then no event afterwards. -static void test_heartbeat_notimeout (int is_curve) +static void +test_heartbeat_notimeout (int is_curve, int client_type, int server_type) { int rc; char my_endpoint[MAX_SOCKET_STRING]; @@ -303,9 +309,9 @@ static void test_heartbeat_notimeout (int is_curve) void *server, *server_mon; prep_server_socket (ctx, 1, is_curve, &server, &server_mon, my_endpoint, - MAX_SOCKET_STRING); + MAX_SOCKET_STRING, server_type); - void *client = zmq_socket (ctx, ZMQ_DEALER); + void *client = zmq_socket (ctx, client_type); if (is_curve) setup_curve (client, 0); rc = zmq_connect (client, my_endpoint); @@ -337,10 +343,26 @@ static void test_heartbeat_notimeout (int is_curve) int main (void) { setup_test_environment (); - test_heartbeat_timeout (); - test_heartbeat_ttl (); + + test_heartbeat_timeout (ZMQ_ROUTER); + test_heartbeat_timeout (ZMQ_REP); + + test_heartbeat_ttl (ZMQ_DEALER, ZMQ_ROUTER); + test_heartbeat_ttl (ZMQ_REQ, ZMQ_REP); + test_heartbeat_ttl (ZMQ_PULL, ZMQ_PUSH); + test_heartbeat_ttl (ZMQ_SUB, ZMQ_PUB); + test_heartbeat_ttl (ZMQ_PAIR, ZMQ_PAIR); + // Run this test without curve - test_heartbeat_notimeout (0); + test_heartbeat_notimeout (0, ZMQ_DEALER, ZMQ_ROUTER); + test_heartbeat_notimeout (0, ZMQ_REQ, ZMQ_REP); + test_heartbeat_notimeout (0, ZMQ_PULL, ZMQ_PUSH); + test_heartbeat_notimeout (0, ZMQ_SUB, ZMQ_PUB); + test_heartbeat_notimeout (0, ZMQ_PAIR, ZMQ_PAIR); // Then rerun it with curve - test_heartbeat_notimeout (1); + test_heartbeat_notimeout (1, ZMQ_DEALER, ZMQ_ROUTER); + test_heartbeat_notimeout (1, ZMQ_REQ, ZMQ_REP); + test_heartbeat_notimeout (1, ZMQ_PULL, ZMQ_PUSH); + test_heartbeat_notimeout (1, ZMQ_SUB, ZMQ_PUB); + test_heartbeat_notimeout (1, ZMQ_PAIR, ZMQ_PAIR); }