Merge pull request #3204 from ctiller/fix-teh-tests

Fixes a couple of tests on Windows
pull/3186/head
Nicolas Noble 10 years ago
commit 2d96240cc4
  1. 4
      test/core/surface/completion_queue_test.c
  2. 29
      test/core/util/port_windows.c

@ -325,7 +325,7 @@ static void test_threading(int producers, int consumers) {
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
grpc_iomgr_init();
grpc_init();
test_no_op();
test_wait_empty();
test_shutdown_then_next_polling();
@ -336,6 +336,6 @@ int main(int argc, char **argv) {
test_threading(1, 10);
test_threading(10, 1);
test_threading(10, 10);
grpc_iomgr_shutdown();
grpc_shutdown();
return 0;
}

@ -52,6 +52,30 @@
#define NUM_RANDOM_PORTS_TO_PICK 100
static int *chosen_ports = NULL;
static size_t num_chosen_ports = 0;
static int has_port_been_chosen(int port) {
size_t i;
for (i = 0; i < num_chosen_ports; i++) {
if (chosen_ports[i] == port) {
return 1;
}
}
return 0;
}
static void free_chosen_ports() { gpr_free(chosen_ports); }
static void chose_port(int port) {
if (chosen_ports == NULL) {
atexit(free_chosen_ports);
}
num_chosen_ports++;
chosen_ports = gpr_realloc(chosen_ports, sizeof(int) * num_chosen_ports);
chosen_ports[num_chosen_ports - 1] = port;
}
static int is_port_available(int *port, int is_tcp) {
const int proto = is_tcp ? IPPROTO_TCP : 0;
const SOCKET fd = socket(AF_INET, is_tcp ? SOCK_STREAM : SOCK_DGRAM, proto);
@ -202,6 +226,10 @@ int grpc_pick_unused_port(void) {
port = 0;
}
if (has_port_been_chosen(port)) {
continue;
}
if (!is_port_available(&port, is_tcp)) {
continue;
}
@ -218,6 +246,7 @@ int grpc_pick_unused_port(void) {
/* TODO(ctiller): consider caching this port in some structure, to avoid
handing it out again */
chose_port(port);
return port;
}

Loading…
Cancel
Save