Removed over-long pauses in tests

- used msleep (10) in most places instead of zmq_sleep (1)
- may cause failures on slower machines
- to change, modify SETTLE_TIME in testutil.h
- tested down to 1 msec on fast boxes

Conflicts:
	tests/test_connect_delay_tipc.cpp
	tests/test_proxy.cpp
	tests/test_sub_forward_tipc.cpp
	tests/test_term_endpoint_tipc.cpp
	tests/testutil.hpp
This commit is contained in:
Pieter Hintjens 2013-11-06 13:30:41 +01:00
parent de239f358e
commit 7f3d0995cd
11 changed files with 31 additions and 18 deletions

View File

@ -45,7 +45,6 @@ int main (int argc, char *argv [])
assert (rc == 0);
int message_count = 20;
for (int j = 0; j < message_count; ++j) {
rc = zmq_send(s_out, (void*)&j, sizeof(int), 0);
if (rc < 0) {
@ -53,15 +52,13 @@ int main (int argc, char *argv [])
return -1;
}
}
zmq_sleep (1);
msleep (SETTLE_TIME);
int payload_recved = 0;
rc = zmq_recv(s_in, (void*)&payload_recved, sizeof(int), 0);
rc = zmq_recv (s_in, (void*)&payload_recved, sizeof(int), 0);
assert (rc > 0);
assert (payload_recved == message_count - 1);
rc = zmq_close (s_in);
assert (rc == 0);

View File

@ -61,7 +61,7 @@ void test_ctx_shutdown()
void *receiver_thread = zmq_threadstart (&receiver, socket);
// Wait for thread to start up and block
zmq_sleep (1);
msleep (SETTLE_TIME);
// Shutdown context, if we used destroy here we would deadlock.
rc = zmq_ctx_shutdown (ctx);

View File

@ -193,8 +193,7 @@ int main (void)
assert (rc == 0);
// Give time to process disconnect
// There's no way to do this except with a sleep
zmq_sleep(1);
msleep (SETTLE_TIME);
// Send a message, should fail
rc = zmq_send (frontend, "Hello", 5, ZMQ_DONTWAIT);

View File

@ -142,7 +142,7 @@ void test_connect_before_bind_pub_sub()
assert (rc == 0);
// Wait for pub-sub connection to happen
zmq_sleep (1);
msleep (SETTLE_TIME);
// Queue up some data, this not will be dropped
rc = zmq_send_const (connectSocket, "after", 6, 0);

View File

@ -80,7 +80,7 @@ int main (void)
rc = zmq_bind (sb, "inproc://a");
assert (rc == 0);
zmq_sleep(1);
msleep (SETTLE_TIME);
void *sc = zmq_socket (ctx, ZMQ_PUSH);
rc = zmq_connect (sc, "inproc://a");

View File

@ -211,7 +211,7 @@ int main (void)
rc = zmq_socket_monitor (req, "inproc://monitor.req", ZMQ_EVENT_ALL);
assert (rc == 0);
threads [1] = zmq_threadstart(&req_socket_monitor, ctx);
zmq_sleep(1);
msleep (SETTLE_TIME);
// Bind REQ and REP
rc = zmq_bind (rep, addr.c_str());
@ -238,8 +238,8 @@ int main (void)
rc = zmq_close (rep);
assert (rc == 0);
// Allow some time for detecting error states
zmq_sleep(1);
// Allow enough time for detecting error states
msleep (250);
// Close the REQ socket
rc = zmq_close (req);

View File

@ -54,7 +54,7 @@ int main (void)
// We have to give the connects time to finish otherwise the requests
// will not properly round-robin. We could alternatively connect the
// REQ sockets to the REP sockets.
zmq_sleep(1);
msleep (SETTLE_TIME);
// Case 1: Second send() before a reply arrives in a pipe.

View File

@ -46,7 +46,7 @@ void test_round_robin_out (void *ctx)
// We have to give the connects time to finish otherwise the requests
// will not properly round-robin. We could alternatively connect the
// REQ sockets to the REP sockets.
zmq_sleep(1);
msleep (SETTLE_TIME);
// Send our peer-replies, and expect every REP it used once in order
for (size_t peer = 0; peer < services; peer++) {

View File

@ -59,7 +59,7 @@ int main (void)
assert (rc >= 0);
// Wait a bit till the subscription gets to the publisher
zmq_sleep(1);
msleep (SETTLE_TIME);
// Send an empty message
rc = zmq_send (pub, NULL, 0, 0);

View File

@ -49,7 +49,7 @@ int main (void)
assert (rc == 0);
// Allow unbind to settle
zmq_sleep(1);
msleep (SETTLE_TIME);
// Check that sending would block (there's no outbound connection)
rc = zmq_send (push, "ABC", 3, ZMQ_DONTWAIT);
@ -86,7 +86,7 @@ int main (void)
assert (rc == 0);
// Allow disconnect to settle
zmq_sleep(1);
msleep (SETTLE_TIME);
// Check that sending would block (there's no inbound connections).
rc = zmq_send (push, "ABC", 3, ZMQ_DONTWAIT);

View File

@ -24,6 +24,11 @@
#include "../include/zmq_utils.h"
#include "platform.hpp"
// 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 10 // In msec
#undef NDEBUG
#include <time.h>
#include <assert.h>
@ -259,4 +264,16 @@ void setup_test_environment()
#endif
}
// Provide portable millisecond sleep
// http://www.cplusplus.com/forum/unices/60161/ http://en.cppreference.com/w/cpp/thread/sleep_for
void msleep (int milliseconds)
{
#ifdef ZMQ_HAVE_WINDOWS
Sleep (milliseconds);
#else
usleep (static_cast <useconds_t> (milliseconds) * 1000);
#endif
}
#endif