diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-04-20 20:52:32 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-04-24 15:06:33 -0700 |
| commit | fdefff742662ed4eb476bf19b9dda245f86bc406 (patch) | |
| tree | a4e132716debd64e434478f8814f368db052cbc6 /tests/respondpoll.c | |
| parent | e0b47b12d3d1462d07c5038e4f34f5282eeec675 (diff) | |
| download | nng-fdefff742662ed4eb476bf19b9dda245f86bc406.tar.gz nng-fdefff742662ed4eb476bf19b9dda245f86bc406.tar.bz2 nng-fdefff742662ed4eb476bf19b9dda245f86bc406.zip | |
fixes #342 Want Surveyor/Respondent context support
fixes #360 core should nng_aio_begin before nng_aio_finish_error
fixes #361 nng_send_aio should check for NULL message
fixes #362 nni_msgq does not signal pollable on certain events
This adds support for contexts for both sides of the surveyor pattern.
Prior to this commit, the raw mode was completely broken, and there
were numerous other bugs found and fixed. This integration includes
*much* deeper validation of this pattern.
Some changes to the core and other patterns have been made, where it
was obvioius that we could make such improvements. (The obviousness
stemming from the fact that RESPONDENT in particular is very closely
derived from REP.)
Diffstat (limited to 'tests/respondpoll.c')
| -rw-r--r-- | tests/respondpoll.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/tests/respondpoll.c b/tests/respondpoll.c new file mode 100644 index 00000000..2e24b5b2 --- /dev/null +++ b/tests/respondpoll.c @@ -0,0 +1,109 @@ +// +// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2018 Capitar IT Group BV <info@capitar.com> +// +// This software is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// + +#include "convey.h" +#include "nng.h" +#include "protocol/survey0/respond.h" +#include "protocol/survey0/survey.h" +#include "stubs.h" +#include "supplemental/util/platform.h" + +TestMain("Respondent pollable", { + + atexit(nng_fini); + + Convey("Given a connected survey pair", { + nng_socket surv; + nng_socket resp; + nng_ctx ctx; + + So(nng_surveyor0_open(&surv) == 0); + So(nng_respondent0_open(&resp) == 0); + So(nng_ctx_open(&ctx, resp) == 0); + + So(nng_setopt_ms(surv, NNG_OPT_SENDTIMEO, 2000) == 0); + So(nng_setopt_ms(resp, NNG_OPT_SENDTIMEO, 2000) == 0); + So(nng_setopt_ms(surv, NNG_OPT_RECVTIMEO, 2000) == 0); + So(nng_setopt_ms(resp, NNG_OPT_RECVTIMEO, 2000) == 0); + + Reset({ + nng_ctx_close(ctx); + nng_close(surv); + nng_close(resp); + }); + So(nng_listen(resp, "inproc://ctx1", NULL, 0) == 0); + + Convey("Respondent ctx not pollable", { + int fd; + + So(nng_ctx_getopt_int(ctx, NNG_OPT_SENDFD, &fd) == + NNG_ENOTSUP); + So(nng_ctx_getopt_int(ctx, NNG_OPT_RECVFD, &fd) == + NNG_ENOTSUP); + }); + + Convey("Respondent starts not writable", { + int fd; + + So(nng_getopt_int(resp, NNG_OPT_SENDFD, &fd) == 0); + So(fdready(fd) == false); + + Convey("And remains unwritable on connect", { + So(nng_dial(surv, "inproc://ctx1", NULL, 0) == + 0); + nng_msleep(100); + So(fdready(fd) == false); + + Convey("Becomes writable after recv", { + nng_msg *m; + So(nng_msg_alloc(&m, 0) == 0); + So(nng_sendmsg(surv, m, 0) == 0); + So(nng_recvmsg(resp, &m, 0) == 0); + nng_msg_free(m); + So(fdready(fd) == true); + }); + }); + }); + + Convey("Respondent starts not readable", { + int fd; + + So(nng_getopt_int(resp, NNG_OPT_RECVFD, &fd) == 0); + So(fdready(fd) == false); + + Convey("And doesn't become readable on connect", { + So(nng_dial(surv, "inproc://ctx1", NULL, 0) == + 0); + nng_msleep(100); + So(fdready(fd) == false); + }); + + Convey("And becomes readable on data", { + nng_msg *msg; + + So(nng_dial(surv, "inproc://ctx1", NULL, 0) == + 0); + nng_msleep(200); + + So(nng_msg_alloc(&msg, 0) == 0); + So(fdready(fd) == false); + So(nng_msg_append(msg, "xyz", 3) == 0); + So(nng_sendmsg(surv, msg, 0) == 0); + nng_msleep(300); // give time for msg to arrive + So(fdready(fd) == true); + Convey("Is no longer readable after recv", { + So(nng_recvmsg(resp, &msg, 0) == 0); + nng_msg_free(msg); + So(fdready(fd) == false); + }); + }); + }); + }); +}); |
