aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-01-05 20:21:52 -0800
committerGarrett D'Amore <garrett@damore.org>2017-01-05 20:21:52 -0800
commitd28f9d935819a88fa799b99362b78a277b74fce8 (patch)
tree612413bfcf85295e1926ffab3bc4011804725266 /tests
parent44f1e3674f56dccb1feb5f0f5a37cb2196f20591 (diff)
downloadnng-d28f9d935819a88fa799b99362b78a277b74fce8.tar.gz
nng-d28f9d935819a88fa799b99362b78a277b74fce8.tar.bz2
nng-d28f9d935819a88fa799b99362b78a277b74fce8.zip
Added test for cancellation, fixed retry bug.
On retry we were pushing back to the queue. The problem with this is that we could wind up pushing back many copies of the message if no reader was present. The new code ensures at most one retry is outstanding.
Diffstat (limited to 'tests')
-rw-r--r--tests/reqrep.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/reqrep.c b/tests/reqrep.c
index fb9a7fb4..d182559d 100644
--- a/tests/reqrep.c
+++ b/tests/reqrep.c
@@ -118,5 +118,58 @@ Main({
nng_msg_free(ping);
})
})
+
+ Convey("Request cancellation works", {
+ nng_msg *abc;
+ nng_msg *def;
+ nng_msg *cmd;
+ nng_msg *nvm;
+ char *body;
+ size_t len;
+ uint64_t retry = 100000; // 100 ms
+
+ nng_socket *req;
+ nng_socket *rep;
+
+ So(nng_open(&rep, NNG_PROTO_REP) == 0);
+ So(rep != NULL);
+
+ So(nng_open(&req, NNG_PROTO_REQ) == 0);
+ So(req != NULL);
+
+ Reset({
+ nng_close(rep);
+ nng_close(req);
+ })
+
+ So(nng_setopt(req, NNG_OPT_RESENDTIME, &retry, sizeof (retry)) == 0);
+ len = 16;
+ So(nng_setopt(req, NNG_OPT_SNDBUF, &len, sizeof (len)) == 0);
+
+ So(nng_msg_alloc(&abc, 0) == 0);
+ So(nng_msg_append(abc, "abc", 4) == 0);
+ So(nng_msg_alloc(&def, 0) == 0);
+ So(nng_msg_append(def, "def", 4) == 0);
+
+ So(nng_dial(req, addr, NULL, 0) == 0);
+
+ So(nng_sendmsg(req, abc, 0) == 0);
+ So(nng_sendmsg(req, def, 0) == 0);
+
+ So(nng_listen(rep, addr, NULL, NNG_FLAG_SYNCH) == 0);
+
+ So(nng_recvmsg(rep, &cmd, 0) == 0);
+ So(cmd != NULL);
+ So(nng_sendmsg(rep, cmd, 0) == 0);
+ So(nng_recvmsg(rep, &cmd, 0) == 0);
+ So(nng_sendmsg(rep, cmd, 0) == 0);
+
+ So(nng_recvmsg(req, &cmd, 0) == 0);
+
+ body = nng_msg_body(cmd, &len);
+ So(len == 4);
+ So(memcmp(body, "def", 4) == 0);
+ nng_msg_free(cmd);
+ })
})
})