aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2015-09-16 17:31:09 -0700
committerGravatar David Garcia Quintas <dgq@google.com>2015-09-16 17:31:09 -0700
commit61d003a15a79fef3b80e10cc40261eacee9477fe (patch)
tree63f0ce1edf3e80c6adec1bebd3ccfd17076c9643 /test/core
parent56d66c207b4317453fa701e1b3fe4e2b32d26355 (diff)
parent1f351c9e1c827b94a87d760e7e5399029738ec98 (diff)
Merge branch 'master' of github.com:grpc/grpc into rr_with_registry
Diffstat (limited to 'test/core')
-rw-r--r--test/core/end2end/dualstack_socket_test.c2
-rw-r--r--test/core/iomgr/udp_server_test.c10
-rw-r--r--test/core/util/port_posix.c92
3 files changed, 90 insertions, 14 deletions
diff --git a/test/core/end2end/dualstack_socket_test.c b/test/core/end2end/dualstack_socket_test.c
index ec3fb65105..fec9667db8 100644
--- a/test/core/end2end/dualstack_socket_test.c
+++ b/test/core/end2end/dualstack_socket_test.c
@@ -267,7 +267,7 @@ void test_connect(const char *server_host, const char *client_host, int port,
int external_dns_works(const char *host) {
grpc_resolved_addresses *res = grpc_blocking_resolve_address(host, "80");
if (res != NULL) {
- gpr_free(res);
+ grpc_resolved_addresses_destroy(res);
return 1;
}
return 0;
diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c
index c4f1896ba6..24b6b1c717 100644
--- a/test/core/iomgr/udp_server_test.c
+++ b/test/core/iomgr/udp_server_test.c
@@ -49,9 +49,7 @@ static grpc_pollset g_pollset;
static int g_number_of_reads = 0;
static int g_number_of_bytes_read = 0;
-static void on_connect(void *arg, grpc_endpoint *udp) {}
-
-static void on_read(int fd, grpc_udp_server_cb new_transport_cb, void *cb_arg) {
+static void on_read(int fd) {
char read_buffer[512];
ssize_t byte_count;
@@ -73,7 +71,7 @@ static void test_no_op(void) {
static void test_no_op_with_start(void) {
grpc_udp_server *s = grpc_udp_server_create();
LOG_TEST("test_no_op_with_start");
- grpc_udp_server_start(s, NULL, 0, on_connect, NULL);
+ grpc_udp_server_start(s, NULL, 0);
grpc_udp_server_destroy(s, NULL, NULL);
}
@@ -100,7 +98,7 @@ static void test_no_op_with_port_and_start(void) {
GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr),
on_read));
- grpc_udp_server_start(s, NULL, 0, on_connect, NULL);
+ grpc_udp_server_start(s, NULL, 0);
grpc_udp_server_destroy(s, NULL, NULL);
}
@@ -130,7 +128,7 @@ static void test_receive(int number_of_clients) {
GPR_ASSERT(addr_len <= sizeof(addr));
pollsets[0] = &g_pollset;
- grpc_udp_server_start(s, pollsets, 1, on_connect, NULL);
+ grpc_udp_server_start(s, pollsets, 1);
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c
index be45bae496..03f4c4912e 100644
--- a/test/core/util/port_posix.c
+++ b/test/core/util/port_posix.c
@@ -47,6 +47,7 @@
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
+#include <grpc/support/string_util.h>
#include "src/core/httpcli/httpcli.h"
#include "src/core/support/env.h"
@@ -66,7 +67,70 @@ static int has_port_been_chosen(int port) {
return 0;
}
-static void free_chosen_ports() { gpr_free(chosen_ports); }
+typedef struct freereq {
+ grpc_pollset pollset;
+ int done;
+} freereq;
+
+static void destroy_pollset_and_shutdown(void *p) {
+ grpc_pollset_destroy(p);
+ grpc_shutdown();
+}
+
+static void freed_port_from_server(void *arg,
+ const grpc_httpcli_response *response) {
+ freereq *pr = arg;
+ gpr_mu_lock(GRPC_POLLSET_MU(&pr->pollset));
+ pr->done = 1;
+ grpc_pollset_kick(&pr->pollset, NULL);
+ gpr_mu_unlock(GRPC_POLLSET_MU(&pr->pollset));
+}
+
+static void free_port_using_server(char *server, int port) {
+ grpc_httpcli_context context;
+ grpc_httpcli_request req;
+ freereq pr;
+ char *path;
+
+ grpc_init();
+
+ memset(&pr, 0, sizeof(pr));
+ memset(&req, 0, sizeof(req));
+ grpc_pollset_init(&pr.pollset);
+
+ req.host = server;
+ gpr_asprintf(&path, "/drop/%d", port);
+ req.path = path;
+
+ grpc_httpcli_context_init(&context);
+ grpc_httpcli_get(&context, &pr.pollset, &req,
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), freed_port_from_server,
+ &pr);
+ gpr_mu_lock(GRPC_POLLSET_MU(&pr.pollset));
+ while (!pr.done) {
+ grpc_pollset_worker worker;
+ grpc_pollset_work(&pr.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC),
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1));
+ }
+ gpr_mu_unlock(GRPC_POLLSET_MU(&pr.pollset));
+
+ grpc_httpcli_context_destroy(&context);
+ grpc_pollset_shutdown(&pr.pollset, destroy_pollset_and_shutdown, &pr.pollset);
+ gpr_free(path);
+}
+
+static void free_chosen_ports() {
+ char *env = gpr_getenv("GRPC_TEST_PORT_SERVER");
+ if (env != NULL) {
+ size_t i;
+ for (i = 0; i < num_chosen_ports; i++) {
+ free_port_using_server(env, chosen_ports[i]);
+ }
+ gpr_free(env);
+ }
+
+ gpr_free(chosen_ports);
+}
static void chose_port(int port) {
if (chosen_ports == NULL) {
@@ -131,6 +195,9 @@ static int is_port_available(int *port, int is_tcp) {
typedef struct portreq {
grpc_pollset pollset;
int port;
+ int retries;
+ char *server;
+ grpc_httpcli_context *ctx;
} portreq;
static void got_port_from_server(void *arg,
@@ -138,6 +205,19 @@ static void got_port_from_server(void *arg,
size_t i;
int port = 0;
portreq *pr = arg;
+ if (!response || response->status != 200) {
+ grpc_httpcli_request req;
+ memset(&req, 0, sizeof(req));
+ GPR_ASSERT(pr->retries < 10);
+ pr->retries++;
+ req.host = pr->server;
+ req.path = "/get";
+ gpr_log(GPR_DEBUG, "failed port pick from server: retrying");
+ sleep(1);
+ grpc_httpcli_get(pr->ctx, &pr->pollset, &req, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10),
+ got_port_from_server, pr);
+ return;
+ }
GPR_ASSERT(response);
GPR_ASSERT(response->status == 200);
for (i = 0; i < response->body_length; i++) {
@@ -151,11 +231,6 @@ static void got_port_from_server(void *arg,
gpr_mu_unlock(GRPC_POLLSET_MU(&pr->pollset));
}
-static void destroy_pollset_and_shutdown(void *p) {
- grpc_pollset_destroy(p);
- grpc_shutdown();
-}
-
static int pick_port_using_server(char *server) {
grpc_httpcli_context context;
grpc_httpcli_request req;
@@ -167,6 +242,8 @@ static int pick_port_using_server(char *server) {
memset(&req, 0, sizeof(req));
grpc_pollset_init(&pr.pollset);
pr.port = -1;
+ pr.server = server;
+ pr.ctx = &context;
req.host = server;
req.path = "/get";
@@ -211,8 +288,9 @@ int grpc_pick_unused_port(void) {
int port = pick_port_using_server(env);
gpr_free(env);
if (port != 0) {
- return port;
+ chose_port(port);
}
+ return port;
}
for (;;) {