aboutsummaryrefslogtreecommitdiff
path: root/tests/bus.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-14 15:27:38 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-14 15:27:38 -0700
commit63479c2938cbc80c1aac9367cb95564f6e7540e1 (patch)
tree495584b637f73b593d25f01577eeaa944477f159 /tests/bus.c
parent343417234aa3fd86e8ae0b56ae500a1ed3411cfc (diff)
downloadnng-63479c2938cbc80c1aac9367cb95564f6e7540e1.tar.gz
nng-63479c2938cbc80c1aac9367cb95564f6e7540e1.tar.bz2
nng-63479c2938cbc80c1aac9367cb95564f6e7540e1.zip
fixes #63 NNG_FLAG_SYNCH should be the default
Also enables creating endpoints that are idle (first part of endpoint options API) and shutting down endpoints.
Diffstat (limited to 'tests/bus.c')
-rw-r--r--tests/bus.c142
1 files changed, 67 insertions, 75 deletions
diff --git a/tests/bus.c b/tests/bus.c
index e96a0a53..d242a7dd 100644
--- a/tests/bus.c
+++ b/tests/bus.c
@@ -8,7 +8,6 @@
//
#include "convey.h"
-#include "core/nng_impl.h"
#include "nng.h"
#include <string.h>
@@ -18,89 +17,82 @@
So(nng_msg_len(m) == strlen(s)); \
So(memcmp(nng_msg_body(m), s, strlen(s)) == 0)
-Main({
+TestMain("BUS pattern", {
const char *addr = "inproc://test";
- atexit(nng_fini);
+ Reset({ nng_fini(); });
- Test("BUS pattern", {
+ Convey("We can create a BUS socket", {
+ nng_socket bus;
- Convey("We can create a BUS socket", {
- nng_socket bus;
+ So(nng_bus_open(&bus) == 0);
- So(nng_bus_open(&bus) == 0);
+ Reset({ nng_close(bus); });
- Reset({ nng_close(bus); });
+ Convey("Protocols match", {
+ So(nng_protocol(bus) == NNG_PROTO_BUS);
+ So(nng_peer(bus) == NNG_PROTO_BUS);
+ });
+ });
+
+ Convey("We can create a linked BUS topology", {
+ nng_socket bus1;
+ nng_socket bus2;
+ nng_socket bus3;
+ uint64_t rtimeo;
+
+ So(nng_bus_open(&bus1) == 0);
+ So(nng_bus_open(&bus2) == 0);
+ So(nng_bus_open(&bus3) == 0);
- Convey("Protocols match", {
- So(nng_protocol(bus) == NNG_PROTO_BUS);
- So(nng_peer(bus) == NNG_PROTO_BUS);
- });
+ Reset({
+ nng_close(bus1);
+ nng_close(bus2);
+ nng_close(bus3);
});
- Convey("We can create a linked BUS topology", {
- nng_socket bus1;
- nng_socket bus2;
- nng_socket bus3;
- uint64_t rtimeo;
-
- So(nng_bus_open(&bus1) == 0);
- So(nng_bus_open(&bus2) == 0);
- So(nng_bus_open(&bus3) == 0);
-
- Reset({
- nng_close(bus1);
- nng_close(bus2);
- nng_close(bus3);
- });
-
- So(nng_listen(bus1, addr, NULL, NNG_FLAG_SYNCH) == 0);
- So(nng_dial(bus2, addr, NULL, NNG_FLAG_SYNCH) == 0);
- So(nng_dial(bus3, addr, NULL, NNG_FLAG_SYNCH) == 0);
-
- rtimeo = 50000;
- So(nng_setopt(bus1, NNG_OPT_RCVTIMEO, &rtimeo,
- sizeof(rtimeo)) == 0);
- rtimeo = 50000;
- So(nng_setopt(bus2, NNG_OPT_RCVTIMEO, &rtimeo,
- sizeof(rtimeo)) == 0);
- rtimeo = 50000;
- So(nng_setopt(bus3, NNG_OPT_RCVTIMEO, &rtimeo,
- sizeof(rtimeo)) == 0);
-
- Convey("Messages delivered", {
- nng_msg *msg;
-
- // This is just a poor man's sleep.
- So(nng_recvmsg(bus1, &msg, 0) ==
- NNG_ETIMEDOUT);
- So(nng_recvmsg(bus2, &msg, 0) ==
- NNG_ETIMEDOUT);
- So(nng_recvmsg(bus3, &msg, 0) ==
- NNG_ETIMEDOUT);
-
- So(nng_msg_alloc(&msg, 0) == 0);
- APPENDSTR(msg, "99bits");
- So(nng_sendmsg(bus2, msg, 0) == 0);
-
- So(nng_recvmsg(bus1, &msg, 0) == 0);
- CHECKSTR(msg, "99bits");
- nng_msg_free(msg);
- So(nng_recvmsg(bus3, &msg, 0) ==
- NNG_ETIMEDOUT);
-
- So(nng_msg_alloc(&msg, 0) == 0);
- APPENDSTR(msg, "onthe");
- So(nng_sendmsg(bus1, msg, 0) == 0);
-
- So(nng_recvmsg(bus2, &msg, 0) == 0);
- CHECKSTR(msg, "onthe");
- nng_msg_free(msg);
-
- So(nng_recvmsg(bus3, &msg, 0) == 0);
- CHECKSTR(msg, "onthe");
- nng_msg_free(msg);
- });
+ So(nng_listen(bus1, addr, NULL, 0) == 0);
+ So(nng_dial(bus2, addr, NULL, 0) == 0);
+ So(nng_dial(bus3, addr, NULL, 0) == 0);
+
+ rtimeo = 50000;
+ So(nng_setopt(
+ bus1, NNG_OPT_RCVTIMEO, &rtimeo, sizeof(rtimeo)) == 0);
+ rtimeo = 50000;
+ So(nng_setopt(
+ bus2, NNG_OPT_RCVTIMEO, &rtimeo, sizeof(rtimeo)) == 0);
+ rtimeo = 50000;
+ So(nng_setopt(
+ bus3, NNG_OPT_RCVTIMEO, &rtimeo, sizeof(rtimeo)) == 0);
+
+ Convey("Messages delivered", {
+ nng_msg *msg;
+
+ // This is just a poor man's sleep.
+ So(nng_recvmsg(bus1, &msg, 0) == NNG_ETIMEDOUT);
+ So(nng_recvmsg(bus2, &msg, 0) == NNG_ETIMEDOUT);
+ So(nng_recvmsg(bus3, &msg, 0) == NNG_ETIMEDOUT);
+
+ So(nng_msg_alloc(&msg, 0) == 0);
+ APPENDSTR(msg, "99bits");
+ So(nng_sendmsg(bus2, msg, 0) == 0);
+
+ So(nng_recvmsg(bus1, &msg, 0) == 0);
+ CHECKSTR(msg, "99bits");
+ nng_msg_free(msg);
+ So(nng_recvmsg(bus3, &msg, 0) == NNG_ETIMEDOUT);
+
+ So(nng_msg_alloc(&msg, 0) == 0);
+ APPENDSTR(msg, "onthe");
+ So(nng_sendmsg(bus1, msg, 0) == 0);
+
+ So(nng_recvmsg(bus2, &msg, 0) == 0);
+ CHECKSTR(msg, "onthe");
+ nng_msg_free(msg);
+
+ So(nng_recvmsg(bus3, &msg, 0) == 0);
+ CHECKSTR(msg, "onthe");
+ nng_msg_free(msg);
});
});
})