From 95123ceb9bc1b4683518a75ad1a0fb8c0b962ab0 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 15 Jun 2016 08:02:38 -0700 Subject: Add a test for multiple endpoint shutdowns --- test/core/iomgr/endpoint_tests.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/core') diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c index 6d15ecf141..b9331fd8fe 100644 --- a/test/core/iomgr/endpoint_tests.c +++ b/test/core/iomgr/endpoint_tests.c @@ -253,6 +253,41 @@ static void read_and_write_test(grpc_endpoint_test_config config, grpc_exec_ctx_finish(&exec_ctx); } +static void must_fail(grpc_exec_ctx *exec_ctx, void *arg, bool success) { + GPR_ASSERT(!success); + ++*(int *)arg; +} + +static void multiple_shutdown_test(grpc_endpoint_test_config config) { + grpc_endpoint_test_fixture f = begin_test(config, "read_and_write_test", 128); + int fail_count = 0; + + gpr_slice_buffer incoming; + gpr_slice_buffer_init(&incoming); + + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_endpoint_read(&exec_ctx, f.client_ep, &incoming, + grpc_closure_create(must_fail, &fail_count)); + grpc_exec_ctx_flush(&exec_ctx); + GPR_ASSERT(fail_count == 0); + grpc_endpoint_shutdown(&exec_ctx, f.client_ep); + grpc_exec_ctx_flush(&exec_ctx); + GPR_ASSERT(fail_count == 1); + grpc_endpoint_read(&exec_ctx, f.client_ep, &incoming, + grpc_closure_create(must_fail, &fail_count)); + grpc_exec_ctx_flush(&exec_ctx); + GPR_ASSERT(fail_count == 2); + grpc_endpoint_shutdown(&exec_ctx, f.client_ep); + grpc_exec_ctx_flush(&exec_ctx); + GPR_ASSERT(fail_count == 2); + + gpr_slice_buffer_destroy(&incoming); + + grpc_endpoint_destroy(&exec_ctx, f.client_ep); + grpc_endpoint_destroy(&exec_ctx, f.server_ep); + grpc_exec_ctx_finish(&exec_ctx); +} + void grpc_endpoint_tests(grpc_endpoint_test_config config, grpc_pollset *pollset, gpr_mu *mu) { size_t i; @@ -264,5 +299,6 @@ void grpc_endpoint_tests(grpc_endpoint_test_config config, for (i = 1; i < 1000; i = GPR_MAX(i + 1, i * 5 / 4)) { read_and_write_test(config, 40320, i, i, 0); } + multiple_shutdown_test(config); g_pollset = NULL; } -- cgit v1.2.3