aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core
diff options
context:
space:
mode:
authorGravatar Dan Born <dborn+github@google.com>2016-01-12 20:29:29 -0800
committerGravatar Dan Born <dborn+github@google.com>2016-01-12 20:29:29 -0800
commit5d81d15260a2f355580bc1ede89c69b456c71f9f (patch)
tree23a334a2c562af5b617d525a91f5f99f3c12cbf1 /test/core
parentfa6b606898b18c22cdcbaa006338fe1d57d8f93f (diff)
Code review follow-up.
Diffstat (limited to 'test/core')
-rw-r--r--test/core/client_config/set_initial_connect_string_test.c4
-rw-r--r--test/core/iomgr/tcp_server_posix_test.c23
-rw-r--r--test/core/util/reconnect_server.c4
-rw-r--r--test/core/util/test_tcp_server.c21
-rw-r--r--test/core/util/test_tcp_server.h1
5 files changed, 23 insertions, 30 deletions
diff --git a/test/core/client_config/set_initial_connect_string_test.c b/test/core/client_config/set_initial_connect_string_test.c
index 68832a4b4e..bf7ef3f26b 100644
--- a/test/core/client_config/set_initial_connect_string_test.c
+++ b/test/core/client_config/set_initial_connect_string_test.c
@@ -79,10 +79,8 @@ static void handle_read(grpc_exec_ctx *exec_ctx, void *arg, int success) {
}
static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp,
- grpc_tcp_server *tcp_server, unsigned port_index,
- unsigned fd_index) {
+ grpc_tcp_server_acceptor *acceptor) {
test_tcp_server *server = arg;
- grpc_tcp_server_unref(NULL, tcp_server);
grpc_closure_init(&on_read, handle_read, NULL);
gpr_slice_buffer_init(&state.incoming_buffer);
gpr_slice_buffer_init(&state.temp_incoming_buffer);
diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c
index 2791087b8a..11848851d8 100644
--- a/test/core/iomgr/tcp_server_posix_test.c
+++ b/test/core/iomgr/tcp_server_posix_test.c
@@ -53,18 +53,17 @@ struct on_connect_result {
};
static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp,
- grpc_tcp_server *tcp_server, unsigned port_index,
- unsigned fd_index) {
+ grpc_tcp_server_acceptor *acceptor) {
struct on_connect_result *result = arg;
grpc_endpoint_shutdown(exec_ctx, tcp);
grpc_endpoint_destroy(exec_ctx, tcp);
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
- result->server_fd = grpc_tcp_server_get_fd(tcp_server, port_index, fd_index);
+ result->server_fd = grpc_tcp_server_port_fd(
+ acceptor->from_server, acceptor->port_index, acceptor->fd_index);
g_nconnects++;
grpc_pollset_kick(&g_pollset, NULL);
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
- grpc_tcp_server_unref(exec_ctx, tcp_server);
}
static void test_no_op(void) {
@@ -133,14 +132,14 @@ static void test_connect(int n) {
addr.ss_family = AF_INET;
GPR_ASSERT(grpc_tcp_server_add_port(s, (struct sockaddr *)&addr, addr_len) >
0);
- GPR_ASSERT(grpc_tcp_server_fds_for_port(s, 2) == 0);
- GPR_ASSERT(grpc_tcp_server_fds_for_port(s, 1) == 0);
- GPR_ASSERT(grpc_tcp_server_fds_for_port(s, 0) == 1);
- GPR_ASSERT(grpc_tcp_server_get_fd(s, 0, 1) < 0);
- GPR_ASSERT(grpc_tcp_server_get_fd(s, 0, 2) < 0);
- GPR_ASSERT(grpc_tcp_server_get_fd(s, 2, 0) < 0);
- GPR_ASSERT(grpc_tcp_server_get_fd(s, 1, 0) < 0);
- svrfd = grpc_tcp_server_get_fd(s, 0, 0);
+ GPR_ASSERT(grpc_tcp_server_port_fd_count(s, 2) == 0);
+ GPR_ASSERT(grpc_tcp_server_port_fd_count(s, 1) == 0);
+ GPR_ASSERT(grpc_tcp_server_port_fd_count(s, 0) == 1);
+ GPR_ASSERT(grpc_tcp_server_port_fd(s, 0, 1) < 0);
+ GPR_ASSERT(grpc_tcp_server_port_fd(s, 0, 2) < 0);
+ GPR_ASSERT(grpc_tcp_server_port_fd(s, 2, 0) < 0);
+ GPR_ASSERT(grpc_tcp_server_port_fd(s, 1, 0) < 0);
+ svrfd = grpc_tcp_server_port_fd(s, 0, 0);
GPR_ASSERT(svrfd >= 0);
GPR_ASSERT(getsockname(svrfd, (struct sockaddr *)&addr, &addr_len) == 0);
GPR_ASSERT(addr_len <= sizeof(addr));
diff --git a/test/core/util/reconnect_server.c b/test/core/util/reconnect_server.c
index 0db25703c4..fa51d810d8 100644
--- a/test/core/util/reconnect_server.c
+++ b/test/core/util/reconnect_server.c
@@ -67,14 +67,12 @@ static void pretty_print_backoffs(reconnect_server *server) {
}
static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp,
- grpc_tcp_server *tcp_server, unsigned port_index,
- unsigned fd_index) {
+ grpc_tcp_server_acceptor *acceptor) {
char *peer;
char *last_colon;
reconnect_server *server = (reconnect_server *)arg;
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
timestamp_list *new_tail;
- grpc_tcp_server_unref(NULL, tcp_server);
peer = grpc_endpoint_get_peer(tcp);
grpc_endpoint_shutdown(exec_ctx, tcp);
grpc_endpoint_destroy(exec_ctx, tcp);
diff --git a/test/core/util/test_tcp_server.c b/test/core/util/test_tcp_server.c
index cd7cd8db6a..52300c1a2d 100644
--- a/test/core/util/test_tcp_server.c
+++ b/test/core/util/test_tcp_server.c
@@ -45,10 +45,17 @@
#include "src/core/iomgr/tcp_server.h"
#include "test/core/util/port.h"
+static void on_server_destroyed(grpc_exec_ctx *exec_ctx, void *data,
+ int success) {
+ test_tcp_server *server = data;
+ server->shutdown = 1;
+}
+
void test_tcp_server_init(test_tcp_server *server,
grpc_tcp_server_cb on_connect, void *user_data) {
grpc_init();
server->tcp_server = NULL;
+ grpc_closure_init(&server->shutdown_complete, on_server_destroyed, server);
server->shutdown = 0;
grpc_pollset_init(&server->pollset);
server->pollsets[0] = &server->pollset;
@@ -65,7 +72,7 @@ void test_tcp_server_start(test_tcp_server *server, int port) {
addr.sin_port = htons((uint16_t)port);
memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
- server->tcp_server = grpc_tcp_server_create(NULL);
+ server->tcp_server = grpc_tcp_server_create(&server->shutdown_complete);
port_added =
grpc_tcp_server_add_port(server->tcp_server, &addr, sizeof(addr));
GPR_ASSERT(port_added == port);
@@ -90,24 +97,14 @@ void test_tcp_server_poll(test_tcp_server *server, int seconds) {
grpc_exec_ctx_finish(&exec_ctx);
}
-static void on_server_destroyed(grpc_exec_ctx *exec_ctx, void *data,
- int success) {
- test_tcp_server *server = data;
- server->shutdown = 1;
-}
-
static void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, int success) {}
void test_tcp_server_destroy(test_tcp_server *server) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_timespec shutdown_deadline;
- grpc_closure server_shutdown_cb;
grpc_closure do_nothing_cb;
- grpc_closure_init(&server_shutdown_cb, on_server_destroyed, server);
- grpc_closure_init(&do_nothing_cb, do_nothing, NULL);
- grpc_tcp_server_set_shutdown_complete(server->tcp_server,
- &server_shutdown_cb);
grpc_tcp_server_unref(&exec_ctx, server->tcp_server);
+ grpc_closure_init(&do_nothing_cb, do_nothing, NULL);
shutdown_deadline = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
gpr_time_from_seconds(5, GPR_TIMESPAN));
while (!server->shutdown &&
diff --git a/test/core/util/test_tcp_server.h b/test/core/util/test_tcp_server.h
index deb65eef11..5299a8f306 100644
--- a/test/core/util/test_tcp_server.h
+++ b/test/core/util/test_tcp_server.h
@@ -39,6 +39,7 @@
typedef struct test_tcp_server {
grpc_tcp_server *tcp_server;
+ grpc_closure shutdown_complete;
int shutdown;
grpc_pollset pollset;
grpc_pollset *pollsets[1];