diff options
| author | Garrett D'Amore <garrett@damore.org> | 2020-01-11 16:25:45 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-01-12 09:39:36 -0800 |
| commit | 5521b6e501c478a6113d6db8424bd89fb612763e (patch) | |
| tree | 4f6f9f1697f7166b9a268b9df250e6d9d2808c7e /src/protocol/reqrep0/rep_test.c | |
| parent | 1b811f68eb0294e947c7b775fd24a239bb44b5b8 (diff) | |
| download | nng-5521b6e501c478a6113d6db8424bd89fb612763e.tar.gz nng-5521b6e501c478a6113d6db8424bd89fb612763e.tar.bz2 nng-5521b6e501c478a6113d6db8424bd89fb612763e.zip | |
Test coverage improvements for REQ/REP.
This also fixes a possible bug if mixing poll file descriptors and
contexts on the same socket. Most folks are unlikely to ever run
into this bug.
At this point the REQ/REP coverage is nearly complete (over 95%).
Diffstat (limited to 'src/protocol/reqrep0/rep_test.c')
| -rw-r--r-- | src/protocol/reqrep0/rep_test.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/protocol/reqrep0/rep_test.c b/src/protocol/reqrep0/rep_test.c index 7c6d6ba0..0eb8b985 100644 --- a/src/protocol/reqrep0/rep_test.c +++ b/src/protocol/reqrep0/rep_test.c @@ -410,6 +410,63 @@ test_rep_close_context_send(void) TEST_NNG_PASS(nng_close(rep)); } +static void +test_rep_ctx_recv_nonblock(void) +{ + nng_socket rep; + nng_ctx ctx; + nng_aio * aio; + + TEST_NNG_PASS(nng_rep0_open(&rep)); + TEST_NNG_PASS(nng_ctx_open(&ctx, rep)); + TEST_NNG_PASS(nng_aio_alloc(&aio, NULL, NULL)); + + nng_aio_set_timeout(aio, 0); // Instant timeout + nng_ctx_recv(ctx, aio); + + nng_aio_wait(aio); + TEST_NNG_FAIL(nng_aio_result(aio), NNG_ETIMEDOUT); + TEST_NNG_PASS(nng_close(rep)); + nng_aio_free(aio); +} + +static void +test_rep_ctx_send_nonblock(void) +{ + nng_socket rep; + nng_socket req; + nng_ctx ctx; + nng_aio * aio; + nng_msg *msg; + + TEST_NNG_PASS(nng_req0_open(&req)); + TEST_NNG_PASS(nng_rep0_open(&rep)); + TEST_NNG_PASS(nng_setopt_ms(req, NNG_OPT_SENDTIMEO, 1000)); + TEST_NNG_PASS(nng_setopt_ms(rep, NNG_OPT_RECVTIMEO, 1000)); + TEST_NNG_PASS(nng_setopt_ms(rep, NNG_OPT_SENDTIMEO, 1000)); + TEST_NNG_PASS(nng_ctx_open(&ctx, rep)); + TEST_NNG_PASS(nng_aio_alloc(&aio, NULL, NULL)); + TEST_NNG_PASS(testutil_marry(req, rep)); + + TEST_NNG_SEND_STR(req, "SEND"); + nng_ctx_recv(ctx, aio); + nng_aio_wait(aio); + TEST_NNG_PASS(nng_aio_result(aio)); + // message carries over + msg = nng_aio_get_msg(aio); + nng_aio_set_msg(aio, msg); + nng_aio_set_timeout(aio, 0); // Instant timeout + nng_ctx_send(ctx, aio); + + nng_aio_wait(aio); + TEST_NNG_FAIL(nng_aio_result(aio), NNG_ETIMEDOUT); + TEST_NNG_PASS(nng_close(rep)); + TEST_NNG_PASS(nng_close(req)); + nng_aio_free(aio); + nng_msg_free(msg); + +} + void test_rep_recv_garbage(void) { @@ -447,6 +504,8 @@ TEST_LIST = { { "rep recv aio ctx stopped", test_rep_ctx_recv_aio_stopped }, { "rep close pipe context send", test_rep_close_pipe_context_send }, { "rep close context send", test_rep_close_context_send }, + { "rep context send nonblock", test_rep_ctx_send_nonblock }, + { "rep context recv nonblock", test_rep_ctx_recv_nonblock }, { "rep recv garbage", test_rep_recv_garbage }, { NULL, NULL }, }; |
