diff options
author | 2015-12-11 14:38:18 -0800 | |
---|---|---|
committer | 2015-12-11 14:38:18 -0800 | |
commit | 10c4b3c70d8816f7e5f395ad214bc815c8f4dfb3 (patch) | |
tree | 883d05038723a7b5fa0b2b382de4bb049f3a5528 /test/core | |
parent | 6f0c1495a5306c5e7ded0b49fc7faabb2a7c2798 (diff) |
Add a test for binding a server to the same port twice; fix crashes
Diffstat (limited to 'test/core')
-rw-r--r-- | test/core/surface/server_test.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/core/surface/server_test.c b/test/core/surface/server_test.c index f180bcdaa1..133d023952 100644 --- a/test/core/surface/server_test.c +++ b/test/core/surface/server_test.c @@ -33,6 +33,8 @@ #include <grpc/grpc.h> #include <grpc/support/log.h> +#include <grpc/support/string_util.h> +#include "test/core/util/port.h" #include "test/core/util/test_config.h" void test_register_method_fail(void) { @@ -58,11 +60,31 @@ void test_request_call_on_no_server_cq(void) { grpc_completion_queue_destroy(cc); } +void test_bind_server_twice(void) { + char *addr; + grpc_server *server1 = grpc_server_create(NULL, NULL); + grpc_server *server2 = grpc_server_create(NULL, NULL); + grpc_completion_queue *cq = grpc_completion_queue_create(NULL); + int port = grpc_pick_unused_port_or_die(); + gpr_asprintf(&addr, "[::]:%d", port); + grpc_server_register_completion_queue(server1, cq, NULL); + grpc_server_register_completion_queue(server2, cq, NULL); + GPR_ASSERT(port == grpc_server_add_insecure_http2_port(server1, addr)); + GPR_ASSERT(0 == grpc_server_add_insecure_http2_port(server2, addr)); + grpc_server_shutdown_and_notify(server1, cq, NULL); + grpc_server_shutdown_and_notify(server2, cq, NULL); + grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL); + grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL); + grpc_server_destroy(server1); + grpc_server_destroy(server2); +} + int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_init(); test_register_method_fail(); test_request_call_on_no_server_cq(); + test_bind_server_twice(); grpc_shutdown(); return 0; } |