mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-10 16:06:09 +00:00
Problem: race condition in test_xpub_nodrop
Solution: try to avoid race condition by increasing timeout from 0 to 250ms
This commit is contained in:
parent
56c94757ff
commit
14fd7505bc
@ -54,7 +54,6 @@ void test ()
|
|||||||
int wait = 1;
|
int wait = 1;
|
||||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (pub, ZMQ_XPUB_NODROP, &wait, 4));
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (pub, ZMQ_XPUB_NODROP, &wait, 4));
|
||||||
|
|
||||||
|
|
||||||
// Create a subscriber
|
// Create a subscriber
|
||||||
void *sub = test_context_socket (ZMQ_SUB);
|
void *sub = test_context_socket (ZMQ_SUB);
|
||||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, "inproc://soname"));
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, "inproc://soname"));
|
||||||
@ -62,6 +61,11 @@ void test ()
|
|||||||
// Subscribe for all messages.
|
// Subscribe for all messages.
|
||||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (sub, ZMQ_SUBSCRIBE, "", 0));
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (sub, ZMQ_SUBSCRIBE, "", 0));
|
||||||
|
|
||||||
|
// we must wait for the subscription to be processed here, so we just
|
||||||
|
// hope SETTLE_TIME suffices; otherwise some or all published messages
|
||||||
|
// might be lost
|
||||||
|
msleep (SETTLE_TIME);
|
||||||
|
|
||||||
int hwmlimit = hwm - 1;
|
int hwmlimit = hwm - 1;
|
||||||
int send_count = 0;
|
int send_count = 0;
|
||||||
|
|
||||||
@ -74,13 +78,19 @@ void test ()
|
|||||||
int recv_count = 0;
|
int recv_count = 0;
|
||||||
do {
|
do {
|
||||||
// Receive the message in the subscriber
|
// Receive the message in the subscriber
|
||||||
int rc = zmq_recv (sub, NULL, 0, ZMQ_DONTWAIT);
|
int rc = zmq_recv (sub, NULL, 0, 0);
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
TEST_ASSERT_EQUAL_INT (EAGAIN, errno);
|
TEST_ASSERT_EQUAL_INT (EAGAIN, errno);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
TEST_ASSERT_EQUAL_INT (0, rc);
|
TEST_ASSERT_EQUAL_INT (0, rc);
|
||||||
recv_count++;
|
recv_count++;
|
||||||
|
|
||||||
|
if (recv_count == 1) {
|
||||||
|
const int sub_rcvtimeo = 250;
|
||||||
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (
|
||||||
|
sub, ZMQ_RCVTIMEO, &sub_rcvtimeo, sizeof (sub_rcvtimeo)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while (true);
|
} while (true);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user