>From 215cfc653e5c6155e231b213534739348152129d Mon Sep 17 00:00:00 2001
From: Martin Sustrik <[email protected]>
Date: Mon, 11 Jul 2011 15:28:02 +0200
Subject: [PATCH] REQ/REP drop test extended

The test now checks whether replies are dropped when reply pipe
is overflowed.

Signed-off-by: Martin Sustrik <[email protected]>
---
 tests/test_reqrep_drop.cpp |   74 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 74 insertions(+), 0 deletions(-)

diff --git a/tests/test_reqrep_drop.cpp b/tests/test_reqrep_drop.cpp
index 353aee7..6531357 100644
--- a/tests/test_reqrep_drop.cpp
+++ b/tests/test_reqrep_drop.cpp
@@ -28,6 +28,8 @@ int main (int argc, char *argv [])
     void *ctx = zmq_init (1);
     assert (ctx);
 
+    //  Check whether requests are discarded because of disconnected requester.
+
     //  Create a server.
     void *xrep = zmq_socket (ctx, ZMQ_XREP);
     assert (xrep);
@@ -62,6 +64,78 @@ int main (int argc, char *argv [])
     //  Clean up.
     rc = zmq_close (xrep);
     assert (rc == 0);
+
+    //  New test. Check whether reply is dropped because of HWM overflow.
+
+    int one = 1;
+    xreq = zmq_socket (ctx, ZMQ_XREQ);
+    assert (xreq);
+    rc = zmq_setsockopt (xreq, ZMQ_RCVHWM, &one, sizeof(one));
+    assert (rc == 0);
+    rc = zmq_bind (xreq, "inproc://a");
+    assert (rc == 0);
+
+    void *rep = zmq_socket (ctx, ZMQ_REP);
+    assert (rep);
+    rc = zmq_setsockopt (rep, ZMQ_SNDHWM, &one, sizeof(one));
+    assert (rc == 0);
+    rc = zmq_connect (rep, "inproc://a");
+    assert (rc == 0);
+
+    //  Send request 1
+    rc = zmq_send (xreq, buff, 1, 0);
+    assert (rc == 1);
+
+    //  Send request 2
+    rc = zmq_send (xreq, buff, 1, 0);
+    assert (rc == 1);
+
+    //  Receive request 1
+    rc = zmq_recv (rep, buff, 1, 0);
+    assert (rc == 1);
+
+    //  Send request 3
+    rc = zmq_send (xreq, buff, 1, 0);
+    assert (rc == 1);
+
+    //  Send reply 1
+    rc = zmq_send (rep, buff, 1, 0);
+    assert (rc == 1);
+
+    //  Receive request 2
+    rc = zmq_recv (rep, buff, 1, 0);
+    assert (rc == 1);
+
+    //  Send reply 2
+    rc = zmq_send (rep, buff, 1, 0);
+    assert (rc == 1);
+
+    //  Receive request 3
+    rc = zmq_recv (rep, buff, 1, 0);
+    assert (rc == 1);
+
+    //  Send reply 3
+    rc = zmq_send (rep, buff, 1, 0);
+    assert (rc == 1);
+
+    //  Receive reply 1
+    rc = zmq_recv (xreq, buff, 1, 0);
+    assert (rc == 1);
+
+    //  Receive reply 2
+    rc = zmq_recv (xreq, buff, 1, 0);
+    assert (rc == 1);
+
+    //  Try to receive reply 3, it should have been dropped.
+    rc = zmq_recv (xreq, buff, 1, ZMQ_DONTWAIT);
+    assert (rc == -1 && errno == EAGAIN);
+
+    //  Clean up.
+    rc = zmq_close (xreq);
+    assert (rc == 0);
+    rc = zmq_close (rep);
+    assert (rc == 0);
+
     rc = zmq_term (ctx);
     assert (rc == 0);
 
-- 
1.7.0.4

_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to