Commit 72b517b3 authored by Luca Boccassi's avatar Luca Boccassi Committed by GitHub

Merge pull request #2704 from sigiesec/fix-test-sockopt-hwm

Problem: test_sockopt_hwm fails occasionally
parents 7283574c 00c69625
......@@ -822,7 +822,7 @@ in linkzmq:zmq_socket[3] for details on the exact action taken for each socket
type.
NOTE: 0MQ does not guarantee that the socket will accept as many as ZMQ_SNDHWM
messages, and the actual limit may be as much as 60-70% lower depending on the
messages, and the actual limit may be as much as 90% lower depending on the
flow of messages on the socket.
[horizontal]
......
......@@ -103,6 +103,25 @@ void test_change_after_connected()
zmq_ctx_term(ctx);
}
int send_until_wouldblock (void *socket)
{
int send_count = 0;
while (send_count < MAX_SENDS
&& zmq_send (socket, &send_count, sizeof (send_count), ZMQ_DONTWAIT)
== sizeof (send_count)) {
++send_count;
}
return send_count;
}
int test_fill_up_to_hwm (void *socket, int sndhwm)
{
int send_count = send_until_wouldblock (socket);
fprintf(stderr, "sndhwm==%i, send_count==%i\n", sndhwm, send_count);
assert (send_count <= sndhwm + 1 && send_count > (sndhwm / 10));
return send_count;
}
void test_decrease_when_full()
{
int rc;
......@@ -115,50 +134,47 @@ void test_decrease_when_full()
rc = zmq_setsockopt(connect_socket, ZMQ_RCVHWM, &val, sizeof(val));
assert(rc == 0);
val = 100;
rc = zmq_setsockopt(bind_socket, ZMQ_SNDHWM, &val, sizeof(val));
assert(rc == 0);
int sndhwm = 100;
rc = zmq_setsockopt (bind_socket, ZMQ_SNDHWM, &sndhwm, sizeof (sndhwm));
assert (rc == 0);
zmq_bind(bind_socket, "inproc://a");
zmq_connect(connect_socket, "inproc://a");
// Fill up to hwm
int send_count = 0;
while (send_count < MAX_SENDS && zmq_send(bind_socket, &send_count, sizeof(send_count), ZMQ_DONTWAIT) == sizeof(send_count))
++send_count;
assert(send_count == 101);
int send_count = test_fill_up_to_hwm (bind_socket, sndhwm);
// Descrease snd hwm
val = 70;
rc = zmq_setsockopt(bind_socket, ZMQ_SNDHWM, &val, sizeof(val));
// Decrease snd hwm
sndhwm = 70;
rc = zmq_setsockopt(bind_socket, ZMQ_SNDHWM, &sndhwm, sizeof(sndhwm));
assert(rc == 0);
size_t placeholder = sizeof(val);
val = 0;
rc = zmq_getsockopt(bind_socket, ZMQ_SNDHWM, &val, &placeholder);
int sndhwm_read = 0;
size_t sndhwm_read_size = sizeof(sndhwm_read);
rc = zmq_getsockopt(bind_socket, ZMQ_SNDHWM, &sndhwm_read, &sndhwm_read_size);
assert(rc == 0);
assert(val == 70);
assert(sndhwm_read == sndhwm);
msleep (SETTLE_TIME);
// Read out all data (should get up to previous hwm worth so none were dropped)
int read_count = 0;
int read_data = 0;
while (read_count < MAX_SENDS && zmq_recv(connect_socket, &read_data, sizeof(read_data), ZMQ_DONTWAIT) == sizeof(read_data)) {
while (
read_count < MAX_SENDS
&& zmq_recv (connect_socket, &read_data, sizeof (read_data), ZMQ_DONTWAIT)
== sizeof (read_data)) {
assert(read_count == read_data);
++read_count;
}
assert(read_count == 101);
assert(read_count == send_count);
// Give io thread some time to catch up
msleep (SETTLE_TIME);
// Fill up to new hwm
send_count = 0;
while (send_count < MAX_SENDS && zmq_send(bind_socket, &send_count, sizeof(send_count), ZMQ_DONTWAIT) == sizeof(send_count))
++send_count;
// Really this should be 71, but the lwm stuff kicks in doesn't seem quite right
assert(send_count > 0);
test_fill_up_to_hwm (bind_socket, sndhwm);
zmq_close(bind_socket);
zmq_close(connect_socket);
......
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