diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-08-24 14:15:48 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-08-24 14:20:34 -0700 |
| commit | c9a68bfe6bea2acc708bf49045f6cb65017a3306 (patch) | |
| tree | e2b93b81b2962bdfb7953cb30fcfae08f0bd4093 /tests/survey.c | |
| parent | 68ff9c823d3cead2b11a003c40c8f5affc11dc71 (diff) | |
| download | nng-c9a68bfe6bea2acc708bf49045f6cb65017a3306.tar.gz nng-c9a68bfe6bea2acc708bf49045f6cb65017a3306.tar.bz2 nng-c9a68bfe6bea2acc708bf49045f6cb65017a3306.zip | |
Eliminate legacy option settings, provide easier option IDs.
This eliminates all the old #define's or enum values, making all
option IDs now totally dynamic, and providing well-known string
values for well-behaved applications.
We have added tests of some of these options, including lookups, and
so forth. We have also fixed a few problems; including at least
one crasher bug when the timeouts on reconnect were zero.
Protocol specific options are now handled in the protocol. We will
be moving the initialization for a few of those well known entities
to the protocol startup code, following the PAIRv1 pattern, later.
Applications must therefore not depend on the value of the integer IDs,
at least until the application has opened a socket of the appropriate
type.
Diffstat (limited to 'tests/survey.c')
| -rw-r--r-- | tests/survey.c | 243 |
1 files changed, 117 insertions, 126 deletions
diff --git a/tests/survey.c b/tests/survey.c index 2bdd2930..ae252cd5 100644 --- a/tests/survey.c +++ b/tests/survey.c @@ -9,142 +9,133 @@ // #include "convey.h" -#include "core/nng_impl.h" #include "nng.h" #include <string.h> +extern const char *nng_opt_surveyor_surveytime; +extern int nng_optid_surveyor_surveytime; + #define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s)) #define CHECKSTR(m, s) \ So(nng_msg_len(m) == strlen(s)); \ So(memcmp(nng_msg_body(m), s, strlen(s)) == 0) -Main({ +TestMain("SURVEY pattern", { const char *addr = "inproc://test"; - nni_init(); - - Test("SURVEY pattern", { - Convey("We can create a SURVEYOR socket", - { - nng_socket surv; - - So(nng_surveyor_open(&surv) == 0); - - Reset({ nng_close(surv); }); - - Convey("Protocols match", { - So(nng_protocol(surv) == - NNG_PROTO_SURVEYOR); - So(nng_peer(surv) == NNG_PROTO_RESPONDENT); - }); - - Convey("Recv with no survey fails", { - nng_msg *msg; - So(nng_recvmsg(surv, &msg, 0) == - NNG_ESTATE); - }); - - Convey("Survey without responder times out", { - uint64_t expire = 50000; - nng_msg *msg; - - So(nng_setopt(surv, NNG_OPT_SURVEYTIME, - &expire, sizeof(expire)) == 0); - So(nng_msg_alloc(&msg, 0) == 0); - So(nng_sendmsg(surv, msg, 0) == 0); - So(nng_recvmsg(surv, &msg, 0) == - NNG_ETIMEDOUT); - }); - }) - - Convey("We can create a RESPONDENT socket", - { - nng_socket resp; - So(nng_respondent_open(&resp) == 0); - - Reset({ nng_close(resp); }); - - Convey("Protocols match", { - So(nng_protocol(resp) == - NNG_PROTO_RESPONDENT); - So(nng_peer(resp) == - NNG_PROTO_SURVEYOR); - }); - - Convey("Send fails with no suvey", { - nng_msg *msg; - So(nng_msg_alloc(&msg, 0) == 0); - So(nng_sendmsg(resp, msg, 0) == - NNG_ESTATE); - nng_msg_free(msg); - }); - }) - - Convey("We can create a linked survey pair", { - nng_socket surv; - nng_socket resp; - nng_socket sock; - uint64_t expire; - - So(nng_surveyor_open(&surv) == 0); - So(nng_respondent_open(&resp) == 0); - - Reset({ - nng_close(surv); - nng_close(resp); - }); - - expire = 50000; - So(nng_setopt(surv, NNG_OPT_SURVEYTIME, - &expire, sizeof(expire)) == 0); - - So(nng_listen(surv, addr, NULL, 0) == 0); - So(nng_dial(resp, addr, NULL, 0) == 0); - - // We dial another socket as that will force - // the earlier dial to have completed *fully*. - // This is a hack that only works because our - // listen logic is single threaded. - So(nng_respondent_open(&sock) == 0); - So(nng_dial(sock, addr, NULL, 0) == 0); - nng_close(sock); - - Convey("Survey works", { - nng_msg *msg; - uint64_t rtimeo; - - So(nng_msg_alloc(&msg, 0) == 0); - APPENDSTR(msg, "abc"); - So(nng_sendmsg(surv, msg, 0) == 0); - msg = NULL; - So(nng_recvmsg(resp, &msg, 0) == 0); - CHECKSTR(msg, "abc"); - nng_msg_chop(msg, 3); - APPENDSTR(msg, "def"); - So(nng_sendmsg(resp, msg, 0) == 0); - msg = NULL; - So(nng_recvmsg(surv, &msg, 0) == 0); - CHECKSTR(msg, "def"); - nng_msg_free(msg); - - So(nng_recvmsg(surv, &msg, 0) == - NNG_ETIMEDOUT); - - Convey( - "And goes to non-survey state", { - rtimeo = 200000; - So(nng_setopt(surv, - NNG_OPT_RCVTIMEO, - &rtimeo, - sizeof(rtimeo)) == - 0); - So(nng_recvmsg(surv, &msg, - 0) == NNG_ESTATE); - }); - }); - }); + atexit(nng_fini); + + Convey("We can create a SURVEYOR socket", { + nng_socket surv; + + So(nng_surveyor_open(&surv) == 0); + + Reset({ nng_close(surv); }); + + Convey("Surveytime option id works", { + int opt; + const char *name; + opt = nng_option_lookup(nng_opt_surveyor_surveytime); + So(opt >= 0); + So(opt == nng_optid_surveyor_surveytime); + name = nng_option_name(opt); + So(name != NULL); + So(strcmp(name, nng_opt_surveyor_surveytime) == 0); + }); + + Convey("Protocols match", { + So(nng_protocol(surv) == NNG_PROTO_SURVEYOR); + So(nng_peer(surv) == NNG_PROTO_RESPONDENT); + }); + + Convey("Recv with no survey fails", { + nng_msg *msg; + So(nng_recvmsg(surv, &msg, 0) == NNG_ESTATE); + }); + + Convey("Survey without responder times out", { + nng_msg *msg; + + So(nng_setopt_usec(surv, nng_optid_surveyor_surveytime, + 50000) == 0); + So(nng_msg_alloc(&msg, 0) == 0); + So(nng_sendmsg(surv, msg, 0) == 0); + So(nng_recvmsg(surv, &msg, 0) == NNG_ETIMEDOUT); + }); }); - nni_fini(); -}) + Convey("We can create a RESPONDENT socket", { + nng_socket resp; + So(nng_respondent_open(&resp) == 0); + + Reset({ nng_close(resp); }); + + Convey("Protocols match", { + So(nng_protocol(resp) == NNG_PROTO_RESPONDENT); + So(nng_peer(resp) == NNG_PROTO_SURVEYOR); + }); + + Convey("Send fails with no suvey", { + nng_msg *msg; + So(nng_msg_alloc(&msg, 0) == 0); + So(nng_sendmsg(resp, msg, 0) == NNG_ESTATE); + nng_msg_free(msg); + }); + }); + + Convey("We can create a linked survey pair", { + nng_socket surv; + nng_socket resp; + nng_socket sock; + + So(nng_surveyor_open(&surv) == 0); + So(nng_respondent_open(&resp) == 0); + + Reset({ + nng_close(surv); + nng_close(resp); + }); + + So(nng_setopt_usec( + surv, nng_optid_surveyor_surveytime, 50000) == 0); + So(nng_listen(surv, addr, NULL, 0) == 0); + So(nng_dial(resp, addr, NULL, 0) == 0); + + // We dial another socket as that will force + // the earlier dial to have completed *fully*. + // This is a hack that only works because our + // listen logic is single threaded. + So(nng_respondent_open(&sock) == 0); + So(nng_dial(sock, addr, NULL, 0) == 0); + nng_close(sock); + + Convey("Survey works", { + nng_msg *msg; + uint64_t rtimeo; + + So(nng_msg_alloc(&msg, 0) == 0); + APPENDSTR(msg, "abc"); + So(nng_sendmsg(surv, msg, 0) == 0); + msg = NULL; + So(nng_recvmsg(resp, &msg, 0) == 0); + CHECKSTR(msg, "abc"); + nng_msg_chop(msg, 3); + APPENDSTR(msg, "def"); + So(nng_sendmsg(resp, msg, 0) == 0); + msg = NULL; + So(nng_recvmsg(surv, &msg, 0) == 0); + CHECKSTR(msg, "def"); + nng_msg_free(msg); + + So(nng_recvmsg(surv, &msg, 0) == NNG_ETIMEDOUT); + + Convey("And goes to non-survey state", { + rtimeo = 200000; + So(nng_setopt_usec(surv, nng_optid_recvtimeo, + 200000) == 0); + So(nng_recvmsg(surv, &msg, 0) == NNG_ESTATE); + }); + }); + }); +}); |
