Commit f20b70be authored by Pieter Hintjens's avatar Pieter Hintjens

Cleaned up test_xpub_nodrop

Renamed test case to actually explain what it's testing, and cleaned up
the code a little.
parent a7fed989
...@@ -134,7 +134,7 @@ test_bind_src_address_SOURCES = test_bind_src_address.cpp ...@@ -134,7 +134,7 @@ test_bind_src_address_SOURCES = test_bind_src_address.cpp
test_metadata_SOURCES = test_metadata.cpp test_metadata_SOURCES = test_metadata.cpp
test_id2fd_SOURCES = test_id2fd.cpp test_id2fd_SOURCES = test_id2fd.cpp
test_capabilities_SOURCES = test_capabilities.cpp test_capabilities_SOURCES = test_capabilities.cpp
test_xpub_wait_inproc_SOURCES = test_xpub_wait_inproc.cpp test_xpub_nodrop_SOURCES = test_xpub_nodrop.cpp
if !ON_MINGW if !ON_MINGW
test_shutdown_stress_SOURCES = test_shutdown_stress.cpp test_shutdown_stress_SOURCES = test_shutdown_stress.cpp
test_pair_ipc_SOURCES = test_pair_ipc.cpp testutil.hpp test_pair_ipc_SOURCES = test_pair_ipc.cpp testutil.hpp
......
...@@ -50,34 +50,33 @@ int main (void) ...@@ -50,34 +50,33 @@ int main (void)
rc = zmq_setsockopt (sub, ZMQ_SUBSCRIBE, "", 0); rc = zmq_setsockopt (sub, ZMQ_SUBSCRIBE, "", 0);
assert (rc == 0); assert (rc == 0);
int hwmlimit = hwm-1; int hwmlimit = hwm - 1;
int send_count = 0; int send_count = 0;
// Send an empty message // Send an empty message
for (int i = 0; i< hwmlimit; i++) { for (int i = 0; i < hwmlimit; i++) {
rc = zmq_send (pub, NULL, 0, 0); rc = zmq_send (pub, NULL, 0, 0);
assert (rc == 0); assert (rc == 0);
send_count++; send_count++;
} }
int recv_count = 0; int recv_count = 0;
do { do {
// Receive the message in the subscriber // Receive the message in the subscriber
// rc = zmq_recv (sub, buff, sizeof (buff), ZMQ_DONTWAIT); rc = zmq_recv (sub, NULL, 0, ZMQ_DONTWAIT);
rc = zmq_recv (sub, NULL, 0, ZMQ_DONTWAIT); if (rc == -1)
if( -1 == rc ) { assert (errno == EAGAIN);
assert(EAGAIN == errno); else {
} assert (rc == 0);
else recv_count++;
{ }
assert( 0 == rc ); }
recv_count++; while (rc == 0);
}
} while( 0 == rc);
assert(send_count == recv_count); assert (send_count == recv_count);
// now test real blocking behavior
// set a timeout, default is infinite // Now test real blocking behavior
// Set a timeout, default is infinite
int timeout = 0; int timeout = 0;
rc = zmq_setsockopt (pub, ZMQ_SNDTIMEO, &timeout, 4); rc = zmq_setsockopt (pub, ZMQ_SNDTIMEO, &timeout, 4);
assert (rc == 0); assert (rc == 0);
...@@ -85,19 +84,15 @@ int main (void) ...@@ -85,19 +84,15 @@ int main (void)
send_count = 0; send_count = 0;
recv_count = 0; recv_count = 0;
hwmlimit = hwm; hwmlimit = hwm;
// Send an empty message
while( 0 == zmq_send (pub, NULL, 0, 0) ) // Send an empty message until we get an error, which must be EAGAIN
{ while (zmq_send (pub, "", 0, 0) == 0)
send_count++; send_count++;
} assert (errno == EAGAIN);
assert( EAGAIN == errno);
while( 0 == zmq_recv (sub, NULL, 0, ZMQ_DONTWAIT))
{
recv_count ++;
}
assert( send_count == recv_count); while (zmq_recv (sub, NULL, 0, ZMQ_DONTWAIT) == 0)
recv_count++;
assert (send_count == recv_count);
// Clean up. // Clean up.
rc = zmq_close (pub); rc = zmq_close (pub);
......
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