From e177512c82c78c930d53209cd2987bc0063a491a Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Fri, 5 Feb 2016 11:56:45 +0000 Subject: [PATCH 01/14] Problem: test_system does not clean up at exit Solution: close socket and destroy context to reduce Valgrind noise --- tests/test_system.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_system.cpp b/tests/test_system.cpp index e82d5b10..60c32ddd 100644 --- a/tests/test_system.cpp +++ b/tests/test_system.cpp @@ -97,4 +97,7 @@ int main (void) for (count = 0; count < 1000; count++) { close(handle[count]); } + + zmq_close(dealer); + zmq_ctx_term(ctx); } From f8f80432229d34712a9e437a42254fe08572ecce Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Fri, 5 Feb 2016 11:57:27 +0000 Subject: [PATCH 02/14] Problem: test_msg_ffn uses unitialised memory Solution: pass correct size to memcmp to avoid reading uninitialised areas of the buffer. --- tests/test_msg_ffn.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_msg_ffn.cpp b/tests/test_msg_ffn.cpp index 4e2cccdd..90736338 100644 --- a/tests/test_msg_ffn.cpp +++ b/tests/test_msg_ffn.cpp @@ -94,7 +94,7 @@ int main (void) { assert (rc > -1); rc = zmq_recv(router, buf, 255, 0); assert (rc == 255); - assert (memcmp(data, buf, 5) == 0); + assert (memcmp(data, buf, 4) == 0); msleep(50); assert (memcmp(hint, "freed", 5) == 0); @@ -115,7 +115,7 @@ int main (void) { assert (rc > -1); rc = zmq_recv(router, buf, 255, 0); assert (rc == 255); - assert (memcmp(data, buf, 5) == 0); + assert (memcmp(data, buf, 4) == 0); rc = zmq_msg_close(&msg2); assert (rc == 0); rc = zmq_msg_close(&msg); From 05ad915265c82c78d5222a0a31563446659d81a2 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Fri, 5 Feb 2016 13:40:59 +0000 Subject: [PATCH 03/14] Problem: test_term_endpoint does not clean up at exit Solution: close socket and destroy context to reduce Valgrind noise --- tests/test_term_endpoint.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_term_endpoint.cpp b/tests/test_term_endpoint.cpp index ff0c1ab1..7a4b15c6 100644 --- a/tests/test_term_endpoint.cpp +++ b/tests/test_term_endpoint.cpp @@ -156,6 +156,14 @@ int main (void) assert (rc == 0); #endif + // Clean up. + rc = zmq_close (pull); + assert (rc == 0); + rc = zmq_close (push); + assert (rc == 0); + rc = zmq_ctx_term (ctx); + assert (rc == 0); + // Create infrastructure (wild-card binding) ctx = zmq_ctx_new (); assert (ctx); @@ -188,5 +196,13 @@ int main (void) assert (rc == -1 && zmq_errno () == ENOENT); #endif + // Clean up. + rc = zmq_close (pull); + assert (rc == 0); + rc = zmq_close (push); + assert (rc == 0); + rc = zmq_ctx_term (ctx); + assert (rc == 0); + return 0; } From cffc65353554efe9a9ea976da8f9de6ebcf892aa Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Fri, 5 Feb 2016 14:39:33 +0000 Subject: [PATCH 04/14] Problem: test_pre_allocated_fd_tcp leaks addrinfo Solution: free addrinfo to reduce Valgrind noise --- tests/test_use_fd_tcp.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_use_fd_tcp.cpp b/tests/test_use_fd_tcp.cpp index db34872d..8357c683 100644 --- a/tests/test_use_fd_tcp.cpp +++ b/tests/test_use_fd_tcp.cpp @@ -55,6 +55,8 @@ void pre_allocate_sock (void *zmq_socket, const char *address, rc = zmq_setsockopt (zmq_socket, ZMQ_USE_FD, &s_pre, sizeof (s_pre)); assert(rc == 0); + + freeaddrinfo(addr); } void test_req_rep () From f87888f80c57a45e247eb662b6e17c1aabccf6ad Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Fri, 5 Feb 2016 14:41:03 +0000 Subject: [PATCH 05/14] Problem: test_router_mandatory_hwm uses unitialised memory Solution: memset temporary buffer before use to reduce Valgrind noise --- tests/test_router_mandatory_hwm.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_router_mandatory_hwm.cpp b/tests/test_router_mandatory_hwm.cpp index 81b8fc63..c2c529a0 100644 --- a/tests/test_router_mandatory_hwm.cpp +++ b/tests/test_router_mandatory_hwm.cpp @@ -83,6 +83,7 @@ int main (void) int i; const int BUF_SIZE = 65536; char buf[BUF_SIZE]; + memset(buf, 0, BUF_SIZE); // Send first batch of messages for(i = 0; i < 100000; ++i) { if (TRACE_ENABLED) fprintf(stderr, "Sending message %d ...\n", i); From 302c7bee506f3a792cd2fc94b2be7d3aed039721 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Fri, 5 Feb 2016 15:14:51 +0000 Subject: [PATCH 06/14] Problem: test_fork does not clean up at exit Solution: close socket and destroy context to reduce Valgrind noise --- tests/test_fork.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_fork.cpp b/tests/test_fork.cpp index 70f4a77c..5370f583 100644 --- a/tests/test_fork.cpp +++ b/tests/test_fork.cpp @@ -86,6 +86,8 @@ int main (void) assert (WEXITSTATUS (child_status) == 0); break; } + zmq_close (pull); + zmq_ctx_term (ctx); exit (0); } #endif From 240190131c70922dc542e1be5a82514dd142a381 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 13 Feb 2016 15:30:20 +0000 Subject: [PATCH 07/14] Problem: test_srcfd uses unitialised memory Solution: memset temporary buffer before use to reduce Valgrind noise --- tests/test_srcfd.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_srcfd.cpp b/tests/test_srcfd.cpp index c219fb3a..fa16256f 100644 --- a/tests/test_srcfd.cpp +++ b/tests/test_srcfd.cpp @@ -62,6 +62,7 @@ int main (void) assert (rc == 0); char tmp[MSG_SIZE]; + memset (tmp, 0, MSG_SIZE); zmq_send(req, tmp, MSG_SIZE, 0); zmq_msg_t msg; From 955b51dfd2727660e18bf28abcd03e1f7cdbcf43 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 13 Feb 2016 15:49:46 +0000 Subject: [PATCH 08/14] Problem: test_msg_ffn uses unitialised memory Solution: memset temporary buffer before use to reduce Valgrind noise --- tests/test_msg_ffn.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_msg_ffn.cpp b/tests/test_msg_ffn.cpp index 90736338..5303637e 100644 --- a/tests/test_msg_ffn.cpp +++ b/tests/test_msg_ffn.cpp @@ -57,6 +57,7 @@ int main (void) { zmq_msg_t msg; char hint[5]; char data[255]; + memset(data, 0, 255); memcpy(data, (void *) "data", 4); memcpy(hint, (void *) "hint", 4); rc = zmq_msg_init_data(&msg, (void *)data, 255, ffn, (void*)hint); From 4a84f8a02ec89e0385ccd250a473d2da52021fba Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 13 Feb 2016 14:23:00 +0000 Subject: [PATCH 09/14] Problem: tests use various sleep patterns to wait Solution: use msleep (SETTLE_TIME) everywhere when waiting for the connections/sockets to be settled instead of a variety of patterns and functions to make tests more coherent. --- tests/test_heartbeats.cpp | 6 +++--- tests/test_hwm_pubsub.cpp | 8 ++++---- tests/test_msg_ffn.cpp | 8 ++++---- tests/test_proxy_terminate.cpp | 2 +- tests/test_radio_dish.cpp | 2 +- tests/test_req_relaxed.cpp | 6 ++---- tests/test_sockopt_hwm.cpp | 2 +- tests/test_spec_dealer.cpp | 15 +++++---------- tests/test_spec_pushpull.cpp | 18 ++++++------------ tests/test_spec_rep.cpp | 6 ++---- tests/test_spec_req.cpp | 12 ++++-------- tests/test_spec_router.cpp | 9 +++------ tests/test_srcfd.cpp | 3 +-- tests/test_udp.cpp | 2 +- tests/test_xpub_manual.cpp | 24 ++++++++++++------------ 15 files changed, 50 insertions(+), 73 deletions(-) diff --git a/tests/test_heartbeats.cpp b/tests/test_heartbeats.cpp index 1a4338d3..3bd4f551 100644 --- a/tests/test_heartbeats.cpp +++ b/tests/test_heartbeats.cpp @@ -39,7 +39,7 @@ get_monitor_event (void *monitor) zmq_msg_t msg; zmq_msg_init (&msg); if (zmq_msg_recv (&msg, monitor, ZMQ_DONTWAIT) == -1) { - msleep(150); + msleep (SETTLE_TIME); continue; // Interruped, presumably } assert (zmq_msg_more (&msg)); @@ -251,7 +251,7 @@ test_heartbeat_ttl (void) rc = get_monitor_event(server_mon); assert(rc == ZMQ_EVENT_ACCEPTED); - msleep(100); + msleep (SETTLE_TIME); // We should have been disconnected rc = get_monitor_event(server_mon); @@ -291,7 +291,7 @@ test_heartbeat_notimeout (int is_curve) rc = zmq_connect(client, "tcp://127.0.0.1:5556"); // Give it a sec to connect and handshake - msleep(100); + msleep (SETTLE_TIME); // By now everything should report as connected rc = get_monitor_event(server_mon); diff --git a/tests/test_hwm_pubsub.cpp b/tests/test_hwm_pubsub.cpp index 8c0ea002..91810aa2 100644 --- a/tests/test_hwm_pubsub.cpp +++ b/tests/test_hwm_pubsub.cpp @@ -180,7 +180,7 @@ void test_reset_hwm () rc = zmq_setsockopt( sub_socket, ZMQ_SUBSCRIBE, 0, 0); assert (rc == 0); - msleep (100); + msleep (SETTLE_TIME); // Send messages int send_count = 0; @@ -188,7 +188,7 @@ void test_reset_hwm () ++send_count; assert (first_count == send_count); - msleep (100); + msleep (SETTLE_TIME); // Now receive all sent messages int recv_count = 0; @@ -198,7 +198,7 @@ void test_reset_hwm () } assert (first_count == recv_count); - msleep (100); + msleep (SETTLE_TIME); // Send messages send_count = 0; @@ -206,7 +206,7 @@ void test_reset_hwm () ++send_count; assert (second_count == send_count); - msleep (100); + msleep (SETTLE_TIME); // Now receive all sent messages recv_count = 0; diff --git a/tests/test_msg_ffn.cpp b/tests/test_msg_ffn.cpp index 5303637e..0208036b 100644 --- a/tests/test_msg_ffn.cpp +++ b/tests/test_msg_ffn.cpp @@ -65,7 +65,7 @@ int main (void) { rc = zmq_msg_close(&msg); assert (rc == 0); - msleep(50); + msleep (SETTLE_TIME); assert (memcmp(hint, "freed", 5) == 0); memcpy(hint, (void *) "hint", 4); @@ -81,7 +81,7 @@ int main (void) { rc = zmq_msg_close(&msg); assert (rc == 0); - msleep(50); + msleep (SETTLE_TIME); assert (memcmp(hint, "freed", 5) == 0); memcpy(hint, (void *) "hint", 4); @@ -97,7 +97,7 @@ int main (void) { assert (rc == 255); assert (memcmp(data, buf, 4) == 0); - msleep(50); + msleep (SETTLE_TIME); assert (memcmp(hint, "freed", 5) == 0); memcpy(hint, (void *) "hint", 4); rc = zmq_msg_close(&msg); @@ -122,7 +122,7 @@ int main (void) { rc = zmq_msg_close(&msg); assert (rc == 0); - msleep(50); + msleep (SETTLE_TIME); assert (memcmp(hint, "freed", 5) == 0); memcpy(hint, (void *) "hint", 4); diff --git a/tests/test_proxy_terminate.cpp b/tests/test_proxy_terminate.cpp index ce494125..b4e19ae5 100644 --- a/tests/test_proxy_terminate.cpp +++ b/tests/test_proxy_terminate.cpp @@ -96,7 +96,7 @@ int main (void) rc = zmq_connect (publisher, "tcp://127.0.0.1:15564"); assert (rc == 0); - msleep (50); + msleep (SETTLE_TIME); rc = zmq_send (publisher, "This is a test", 14, 0); assert (rc == 14); diff --git a/tests/test_radio_dish.cpp b/tests/test_radio_dish.cpp index 18183ac0..e5e371fd 100644 --- a/tests/test_radio_dish.cpp +++ b/tests/test_radio_dish.cpp @@ -117,7 +117,7 @@ int main (void) rc = zmq_connect (dish, "tcp://127.0.0.1:5556"); assert (rc == 0); - zmq_sleep (1); + msleep (SETTLE_TIME); zmq_msg_t msg; diff --git a/tests/test_req_relaxed.cpp b/tests/test_req_relaxed.cpp index 924de7a9..86d99b4e 100644 --- a/tests/test_req_relaxed.cpp +++ b/tests/test_req_relaxed.cpp @@ -103,8 +103,7 @@ int main (void) s_send_seq (rep [3], "BAD", SEQ_END); // Wait for message to be there. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); // Without receiving that reply, send another request on the REQ socket s_send_seq (req, "I", SEQ_END); @@ -127,8 +126,7 @@ int main (void) close_zero_linger (rep [peer]); // Wait for disconnects. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); rc = zmq_ctx_term (ctx); assert (rc == 0); diff --git a/tests/test_sockopt_hwm.cpp b/tests/test_sockopt_hwm.cpp index c9b6fa2f..79c9c5c4 100644 --- a/tests/test_sockopt_hwm.cpp +++ b/tests/test_sockopt_hwm.cpp @@ -150,7 +150,7 @@ void test_decrease_when_full() assert(read_count == 101); // Give io thread some time to catch up - msleep(10); + msleep (SETTLE_TIME); // Fill up to new hwm send_count = 0; diff --git a/tests/test_spec_dealer.cpp b/tests/test_spec_dealer.cpp index 71bf3d33..92f1923e 100644 --- a/tests/test_spec_dealer.cpp +++ b/tests/test_spec_dealer.cpp @@ -55,8 +55,7 @@ void test_round_robin_out (void *ctx) } // Wait for connections. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); // Send all requests for (size_t i = 0; i < services; ++i) @@ -78,8 +77,7 @@ void test_round_robin_out (void *ctx) close_zero_linger (rep [peer]); // Wait for disconnects. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); } void test_fair_queue_in (void *ctx) @@ -122,8 +120,7 @@ void test_fair_queue_in (void *ctx) s_send_seq (senders [peer], "B", SEQ_END); // Wait for data. - rc = zmq_poll (0, 0, 50); - assert (rc == 0); + msleep (SETTLE_TIME); // handle the requests for (size_t peer = 0; peer < services; ++peer) @@ -138,8 +135,7 @@ void test_fair_queue_in (void *ctx) close_zero_linger (senders [peer]); // Wait for disconnects. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); } void test_destroy_queue_on_disconnect (void *ctx) @@ -201,8 +197,7 @@ void test_destroy_queue_on_disconnect (void *ctx) close_zero_linger (B); // Wait for disconnects. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); } void test_block_on_send_no_peers (void *ctx) diff --git a/tests/test_spec_pushpull.cpp b/tests/test_spec_pushpull.cpp index ffe054c0..1cfa7f63 100644 --- a/tests/test_spec_pushpull.cpp +++ b/tests/test_spec_pushpull.cpp @@ -55,8 +55,7 @@ void test_push_round_robin_out (void *ctx) } // Wait for connections. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); // Send 2N messages for (size_t peer = 0; peer < services; ++peer) @@ -76,8 +75,7 @@ void test_push_round_robin_out (void *ctx) close_zero_linger (pulls [peer]); // Wait for disconnects. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); } void test_pull_fair_queue_in (void *ctx) @@ -100,8 +98,7 @@ void test_pull_fair_queue_in (void *ctx) } // Wait for connections. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); int first_half = 0; int second_half = 0; @@ -122,8 +119,7 @@ void test_pull_fair_queue_in (void *ctx) } // Wait for data. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); zmq_msg_t msg; rc = zmq_msg_init (&msg); @@ -156,8 +152,7 @@ void test_pull_fair_queue_in (void *ctx) close_zero_linger (pushs [peer]); // Wait for disconnects. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); } void test_push_block_on_send_no_peers (void *ctx) @@ -260,8 +255,7 @@ void test_destroy_queue_on_disconnect (void *ctx) close_zero_linger (B); // Wait for disconnects. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); } int main (void) diff --git a/tests/test_spec_rep.cpp b/tests/test_spec_rep.cpp index 27d0b35b..75274554 100644 --- a/tests/test_spec_rep.cpp +++ b/tests/test_spec_rep.cpp @@ -94,8 +94,7 @@ void test_fair_queue_in (void *ctx) close_zero_linger (reqs [peer]); // Wait for disconnects. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); } void test_envelope (void *ctx) @@ -128,8 +127,7 @@ void test_envelope (void *ctx) close_zero_linger (dealer); // Wait for disconnects. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); } int main (void) diff --git a/tests/test_spec_req.cpp b/tests/test_spec_req.cpp index 30101809..1cec67f9 100644 --- a/tests/test_spec_req.cpp +++ b/tests/test_spec_req.cpp @@ -71,8 +71,7 @@ void test_round_robin_out (void *ctx) close_zero_linger (rep [peer]); // Wait for disconnects. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); } void test_req_only_listens_to_current_peer (void *ctx) @@ -106,8 +105,7 @@ void test_req_only_listens_to_current_peer (void *ctx) } // Wait for connects to finish. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); for (size_t i = 0; i < services; ++i) { // There still is a race condition when a stale peer's message @@ -137,8 +135,7 @@ void test_req_only_listens_to_current_peer (void *ctx) close_zero_linger (router [i]); // Wait for disconnects. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); } void test_req_message_format (void *ctx) @@ -196,8 +193,7 @@ void test_req_message_format (void *ctx) close_zero_linger (router); // Wait for disconnects. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); } void test_block_on_send_no_peers (void *ctx) diff --git a/tests/test_spec_router.cpp b/tests/test_spec_router.cpp index 68577ad1..6d47927a 100644 --- a/tests/test_spec_router.cpp +++ b/tests/test_spec_router.cpp @@ -104,8 +104,7 @@ void test_fair_queue_in (void *ctx) close_zero_linger (senders [peer]); // Wait for disconnects. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); } void test_destroy_queue_on_disconnect (void *ctx) @@ -130,8 +129,7 @@ void test_destroy_queue_on_disconnect (void *ctx) assert (rc == 0); // Wait for connection. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); // Send a message in both directions s_send_seq (A, "B", "ABC", SEQ_END); @@ -178,8 +176,7 @@ void test_destroy_queue_on_disconnect (void *ctx) close_zero_linger (B); // Wait for disconnects. - rc = zmq_poll (0, 0, 100); - assert (rc == 0); + msleep (SETTLE_TIME); } diff --git a/tests/test_srcfd.cpp b/tests/test_srcfd.cpp index fa16256f..f99ec81e 100644 --- a/tests/test_srcfd.cpp +++ b/tests/test_srcfd.cpp @@ -34,7 +34,6 @@ #ifdef _WIN32 #include #include -#define usleep(a) Sleep((a) / 1000) #else #include #include @@ -102,7 +101,7 @@ int main (void) assert (rc == 0); // sleep a bit for the socket to be freed - usleep(30000); + msleep (SETTLE_TIME); // getting name from closed socket will fail rc = getpeername (srcFd, (struct sockaddr*) &ss, &addrlen); diff --git a/tests/test_udp.cpp b/tests/test_udp.cpp index a49e2b2e..6a48b562 100644 --- a/tests/test_udp.cpp +++ b/tests/test_udp.cpp @@ -98,7 +98,7 @@ int main (void) rc = zmq_bind (dish, "udp://127.0.0.1:5556"); assert (rc == 0); - zmq_sleep (1); + msleep (SETTLE_TIME); rc = zmq_join (dish, "TV"); assert (rc == 0); diff --git a/tests/test_xpub_manual.cpp b/tests/test_xpub_manual.cpp index 35b0e8f1..e30ba857 100644 --- a/tests/test_xpub_manual.cpp +++ b/tests/test_xpub_manual.cpp @@ -124,7 +124,7 @@ int test_xpub_proxy_unsubscribe_on_disconnect() assert (zmq_setsockopt (sub1, ZMQ_SUBSCRIBE, topic, 1) == 0); // wait - assert (zmq_poll (0, 0, 100) == 0); + msleep (SETTLE_TIME); // proxy reroutes and confirms subscriptions char sub_buff[2]; @@ -141,7 +141,7 @@ int test_xpub_proxy_unsubscribe_on_disconnect() assert (zmq_setsockopt (sub2, ZMQ_SUBSCRIBE, topic, 1) == 0); // wait - assert (zmq_poll (0, 0, 100) == 0); + msleep (SETTLE_TIME); // proxy reroutes assert (zmq_recv (xpub_proxy, sub_buff, 2, ZMQ_DONTWAIT) == 2); @@ -151,14 +151,14 @@ int test_xpub_proxy_unsubscribe_on_disconnect() assert (zmq_send (xsub_proxy, sub_buff, 2, 0) == 2); // wait - assert (zmq_poll (0, 0, 100) == 0); + msleep (SETTLE_TIME); // let publisher send a msg assert (zmq_send (pub, topic, 1, ZMQ_SNDMORE) == 1); assert (zmq_send (pub, payload, 1, 0) == 1); // wait - assert (zmq_poll (0, 0, 100) == 0); + msleep (SETTLE_TIME); // proxy reroutes data messages to subscribers char topic_buff[1]; @@ -171,7 +171,7 @@ int test_xpub_proxy_unsubscribe_on_disconnect() assert (zmq_send (xpub_proxy, data_buff, 1, 0) == 1); // wait - assert (zmq_poll (0, 0, 100) == 0); + msleep (SETTLE_TIME); // each subscriber should now get a message assert (zmq_recv (sub2, topic_buff, 1, ZMQ_DONTWAIT) == 1); @@ -189,7 +189,7 @@ int test_xpub_proxy_unsubscribe_on_disconnect() assert (zmq_close (sub2) == 0); // wait - assert (zmq_poll (0, 0, 100) == 0); + msleep (SETTLE_TIME); // unsubscribe messages are passed from proxy to publisher assert (zmq_recv (xpub_proxy, sub_buff, 2, 0) == 2); @@ -207,14 +207,14 @@ int test_xpub_proxy_unsubscribe_on_disconnect() assert (zmq_send (xsub_proxy, sub_buff, 2, 0) == 2); // wait - assert (zmq_poll (0, 0, 100) == 0); + msleep (SETTLE_TIME); // let publisher send a msg assert (zmq_send (pub, topic, 1, ZMQ_SNDMORE) == 1); assert (zmq_send (pub, payload, 1, 0) == 1); // wait - assert (zmq_poll (0, 0, 100) == 0); + msleep (SETTLE_TIME); // nothing should come to the proxy assert (zmq_recv (xsub_proxy, topic_buff, 1, ZMQ_DONTWAIT) == -1); @@ -273,7 +273,7 @@ int test_missing_subscriptions() assert (zmq_setsockopt (sub2, ZMQ_SUBSCRIBE, topic2, 1) == 0); // wait - assert (zmq_poll (0, 0, 100) == 0); + msleep (SETTLE_TIME); // proxy now reroutes and confirms subscriptions char buffer[2]; @@ -290,7 +290,7 @@ int test_missing_subscriptions() assert (zmq_send (xsub_proxy, buffer, 2, 0) == 2); // wait - assert (zmq_poll (0, 0, 100) == 0); + msleep (SETTLE_TIME); // let publisher send 2 msgs, each with its own topic assert (zmq_send (pub, topic1, 1, ZMQ_SNDMORE) == 1); @@ -299,7 +299,7 @@ int test_missing_subscriptions() assert (zmq_send (pub, payload, 1, 0) == 1); // wait - assert (zmq_poll (0, 0, 100) == 0); + msleep (SETTLE_TIME); // proxy reroutes data messages to subscribers char topic_buff [1]; @@ -319,7 +319,7 @@ int test_missing_subscriptions() assert (zmq_send (xpub_proxy, data_buff, 1, 0) == 1); // wait - assert (zmq_poll (0, 0, 100) == 0); + msleep (SETTLE_TIME); // each subscriber should now get a message assert (zmq_recv (sub2, topic_buff, 1, ZMQ_DONTWAIT) == 1); From cb4120188077ce35721271cb15783498ea0ebb63 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 13 Feb 2016 14:25:57 +0000 Subject: [PATCH 10/14] Problem: various tests fail in slow environments Solution: add msleep (SETTLE_TIME) to test_immediate, test_spec_rep and test_spec_router after the sockets are created and connected to avoid failing when running in slower environment like through Valgrind in underpowered VMs. --- tests/test_immediate.cpp | 2 ++ tests/test_spec_rep.cpp | 2 ++ tests/test_spec_router.cpp | 2 ++ 3 files changed, 6 insertions(+) diff --git a/tests/test_immediate.cpp b/tests/test_immediate.cpp index 3c150d79..d0fbaaf6 100644 --- a/tests/test_immediate.cpp +++ b/tests/test_immediate.cpp @@ -67,6 +67,8 @@ int main (void) rc = zmq_connect (from, "tcp://localhost:6555"); assert (rc == 0); + msleep (SETTLE_TIME); + // We send 10 messages, 5 should just get stuck in the queue // for the not-yet-connected pipe for (int i = 0; i < 10; ++i) { diff --git a/tests/test_spec_rep.cpp b/tests/test_spec_rep.cpp index 75274554..1b2de517 100644 --- a/tests/test_spec_rep.cpp +++ b/tests/test_spec_rep.cpp @@ -57,6 +57,8 @@ void test_fair_queue_in (void *ctx) assert (rc == 0); } + msleep (SETTLE_TIME); + s_send_seq (reqs [0], "A", SEQ_END); s_recv_seq (rep, "A", SEQ_END); s_send_seq (rep, "A", SEQ_END); diff --git a/tests/test_spec_router.cpp b/tests/test_spec_router.cpp index 6d47927a..fadecdfe 100644 --- a/tests/test_spec_router.cpp +++ b/tests/test_spec_router.cpp @@ -63,6 +63,8 @@ void test_fair_queue_in (void *ctx) assert (rc == 0); } + msleep (SETTLE_TIME); + zmq_msg_t msg; rc = zmq_msg_init (&msg); assert (rc == 0); From 63a0924484931e7fbc2c75313a12e90c4fc08803 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 13 Feb 2016 15:46:54 +0000 Subject: [PATCH 11/14] Problem: test_sockopt_hwm not renamed in gitignore Solution: rename from test_socketopt_hwm to test_sockopt_hwm in .gitignore too --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4fb611c5..53a23470 100644 --- a/.gitignore +++ b/.gitignore @@ -28,7 +28,7 @@ autom4te.cache curve_keygen test_heartbeats test_msg_ffn -test_socketopt_hwm +test_sockopt_hwm test_resource test_ipc_wildcard test_stream_empty From 706c3b7c4bc4ff6c871be29c436e5e2fcee071c6 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 13 Feb 2016 17:42:19 +0000 Subject: [PATCH 12/14] Problem: test_shutdown_stress_tipc broken on OSX/Cmake Solution: include pthread.h in testutil.hpp, removed from test_shutdown_stress_tipc in an earlier commit --- tests/testutil.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testutil.hpp b/tests/testutil.hpp index 066a9286..0ab01bbd 100644 --- a/tests/testutil.hpp +++ b/tests/testutil.hpp @@ -56,6 +56,7 @@ # pragma warning(disable:4996) # endif #else +# include # include # include # include From 217f6c438ed1937c011d504e0c0fdcb75ca0001a Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 13 Feb 2016 18:04:25 +0000 Subject: [PATCH 13/14] Problem: tests README does not document msleep Solution: suggest to use the common approach of msleep (SETTLE_TIME) after a connect if necessary, rather than reimplementing a different way. --- tests/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/README.md b/tests/README.md index a9463ef4..791ca386 100644 --- a/tests/README.md +++ b/tests/README.md @@ -11,3 +11,8 @@ Note that testutil.hpp includes platform.h. Do not include it yourself as it cha All sources must contain the correct header. Please copy from test_system.cpp if you're not certain. Please use only ANSI C99 in test cases, no C++. This is to make the code more reusable. + +On many slower environments, like embedded systems, VMs or CI systems, test might +fail because it takes time for sockets to settle after a connect. If you need +to add a sleep, please be consistent with all the other tests and use: + msleep (SETTLE_TIME); \ No newline at end of file From facb5121056bb0720ed9c26642538fe0f4397303 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 13 Feb 2016 14:33:58 +0000 Subject: [PATCH 14/14] Problem: SETTLE_TIME is too short on slow systems Solution: increase SETTLE_TIME from 50ms to 300ms to avoid failing on slower environments like through Valgrind on slow VMs. --- tests/testutil.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testutil.hpp b/tests/testutil.hpp index 0ab01bbd..e1454ceb 100644 --- a/tests/testutil.hpp +++ b/tests/testutil.hpp @@ -41,7 +41,7 @@ // This defines the settle time used in tests; raise this if we // get test failures on slower systems due to binds/connects not // settled. Tested to work reliably at 1 msec on a fast PC. -#define SETTLE_TIME 50 // In msec +#define SETTLE_TIME 300 // In msec #undef NDEBUG #include