diff options
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 }, }; |
