Add a test for binding a server to the same port twice; fix crashes

pull/4433/head
Craig Tiller 9 years ago
parent 6f0c1495a5
commit 10c4b3c70d
  1. 8
      src/core/iomgr/tcp_server_posix.c
  2. 22
      test/core/surface/server_test.c

@ -532,8 +532,12 @@ void grpc_tcp_server_start(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s,
}
int grpc_tcp_listener_get_port(grpc_tcp_listener *listener) {
grpc_tcp_listener *sp = listener;
return sp->port;
if (listener != NULL) {
grpc_tcp_listener *sp = listener;
return sp->port;
} else {
return 0;
}
}
void grpc_tcp_listener_ref(grpc_tcp_listener *listener) {

@ -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;
}

Loading…
Cancel
Save