aboutsummaryrefslogtreecommitdiff
path: root/tests/pubsub.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/pubsub.c')
-rw-r--r--tests/pubsub.c45
1 files changed, 35 insertions, 10 deletions
diff --git a/tests/pubsub.c b/tests/pubsub.c
index bd0d7f56..2151611d 100644
--- a/tests/pubsub.c
+++ b/tests/pubsub.c
@@ -146,19 +146,44 @@ TestMain("PUB/SUB pattern", {
So(nng_recvmsg(sub, &msg, 0) == NNG_ETIMEDOUT);
});
- Convey("Subs in raw receive", {
+ });
- nng_msg *msg;
+ Convey("Subs in raw receive", {
- So(nng_setopt_ms(sub, NNG_OPT_RECVTIMEO, 90) == 0);
- So(nng_setopt_bool(sub, NNG_OPT_RAW, true) == 0);
+ nng_msg * msg;
+ nng_socket pub;
+ nng_socket sub;
+ bool raw;
- So(nng_msg_alloc(&msg, 0) == 0);
- APPENDSTR(msg, "/some/like/it/raw");
- So(nng_sendmsg(pub, msg, 0) == 0);
- So(nng_recvmsg(sub, &msg, 0) == 0);
- CHECKSTR(msg, "/some/like/it/raw");
- nng_msg_free(msg);
+ So(nng_pub_open(&pub) == 0);
+
+ So(nng_sub_open_raw(&sub) == 0);
+
+ Reset({
+ nng_close(pub);
+ nng_close(sub);
});
+
+ // Most applications will usually have the pub listen,
+ // and the sub dial. However, this creates a problem
+ // for our tests, since we can wind up trying to push
+ // data before the pipe is fully registered (the accept
+ // runs asynchronously.)
+ So(nng_listen(sub, addr, NULL, 0) == 0);
+ So(nng_dial(pub, addr, NULL, 0) == 0);
+
+ nng_msleep(20); // give time for connecting threads
+
+ So(nng_setopt_ms(sub, NNG_OPT_RECVTIMEO, 90) == 0);
+ So(nng_getopt_bool(sub, NNG_OPT_RAW, &raw) == 0);
+ So(raw == true);
+
+ So(nng_msg_alloc(&msg, 0) == 0);
+ APPENDSTR(msg, "/some/like/it/raw");
+ So(nng_sendmsg(pub, msg, 0) == 0);
+ So(nng_recvmsg(sub, &msg, 0) == 0);
+ CHECKSTR(msg, "/some/like/it/raw");
+ nng_msg_free(msg);
});
+
})