Skip to content

Commit

Permalink
Merge pull request zeromq#1804 from bluca/test_fixes
Browse files Browse the repository at this point in the history
Various test fixes
  • Loading branch information
hintjens committed Feb 13, 2016
2 parents 18dcc32 + facb512 commit 93f99d0
Show file tree
Hide file tree
Showing 24 changed files with 92 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 2 additions & 0 deletions tests/test_fork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ int main (void)
assert (WEXITSTATUS (child_status) == 0);
break;
}
zmq_close (pull);
zmq_ctx_term (ctx);
exit (0);
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions tests/test_heartbeats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions tests/test_hwm_pubsub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ 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;
while (send_count < first_count && zmq_send (pub_socket, NULL, 0, ZMQ_DONTWAIT) == 0)
++send_count;
assert (first_count == send_count);

msleep (100);
msleep (SETTLE_TIME);

// Now receive all sent messages
int recv_count = 0;
Expand All @@ -198,15 +198,15 @@ void test_reset_hwm ()
}
assert (first_count == recv_count);

msleep (100);
msleep (SETTLE_TIME);

// Send messages
send_count = 0;
while (send_count < second_count && zmq_send (pub_socket, NULL, 0, ZMQ_DONTWAIT) == 0)
++send_count;
assert (second_count == send_count);

msleep (100);
msleep (SETTLE_TIME);

// Now receive all sent messages
recv_count = 0;
Expand Down
2 changes: 2 additions & 0 deletions tests/test_immediate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 7 additions & 6 deletions tests/test_msg_ffn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ 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);
assert (rc == 0);
rc = zmq_msg_close(&msg);
assert (rc == 0);

msleep(50);
msleep (SETTLE_TIME);
assert (memcmp(hint, "freed", 5) == 0);
memcpy(hint, (void *) "hint", 4);

Expand All @@ -80,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);

Expand All @@ -94,9 +95,9 @@ 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);
msleep (SETTLE_TIME);
assert (memcmp(hint, "freed", 5) == 0);
memcpy(hint, (void *) "hint", 4);
rc = zmq_msg_close(&msg);
Expand All @@ -115,13 +116,13 @@ 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);
assert (rc == 0);

msleep(50);
msleep (SETTLE_TIME);
assert (memcmp(hint, "freed", 5) == 0);
memcpy(hint, (void *) "hint", 4);

Expand Down
2 changes: 1 addition & 1 deletion tests/test_proxy_terminate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/test_radio_dish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 2 additions & 4 deletions tests/test_req_relaxed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions tests/test_router_mandatory_hwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sockopt_hwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 5 additions & 10 deletions tests/test_spec_dealer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 6 additions & 12 deletions tests/test_spec_pushpull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_spec_rep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -94,8 +96,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)
Expand Down Expand Up @@ -128,8 +129,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)
Expand Down
12 changes: 4 additions & 8 deletions tests/test_spec_req.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 93f99d0

Please sign in to comment.