aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/end2end/dualstack_socket_test.c
diff options
context:
space:
mode:
authorGravatar David Klempner <klempner@google.com>2015-02-25 13:37:12 -0800
committerGravatar David Klempner <klempner@google.com>2015-02-25 13:37:12 -0800
commit57c0061d782cb9ff45583c942eceb8b96896df80 (patch)
treee9132ef5bb045739351746648a393d212dc813be /test/core/end2end/dualstack_socket_test.c
parent3c17f04af914777e20cf01b8e44e693486b02e98 (diff)
Deflake dualstack socket test
The test currently allocates a single port and reuses it through the test. Given the timeouts in this test this leaves substantial race windows where other processes on the same machine could steal the port between subcases. Instead, as a simple hack, allocate a new port before each test.
Diffstat (limited to 'test/core/end2end/dualstack_socket_test.c')
-rw-r--r--test/core/end2end/dualstack_socket_test.c51
1 files changed, 25 insertions, 26 deletions
diff --git a/test/core/end2end/dualstack_socket_test.c b/test/core/end2end/dualstack_socket_test.c
index 62676d01e0..5e2c80af5a 100644
--- a/test/core/end2end/dualstack_socket_test.c
+++ b/test/core/end2end/dualstack_socket_test.c
@@ -75,6 +75,10 @@ void test_connect(const char *server_host, const char *client_host, int port,
gpr_timespec deadline;
int got_port;
+ if (port == 0) {
+ port = grpc_pick_unused_port_or_die();
+ }
+
gpr_join_host_port(&server_hostport, server_host, port);
/* Create server. */
@@ -179,7 +183,6 @@ void test_connect(const char *server_host, const char *client_host, int port,
int main(int argc, char **argv) {
int do_ipv6 = 1;
- int fixed_port;
grpc_test_init(argc, argv);
grpc_init();
@@ -189,32 +192,28 @@ int main(int argc, char **argv) {
do_ipv6 = 0;
}
- for (fixed_port = 0; fixed_port <= 1; fixed_port++) {
- int port = fixed_port ? grpc_pick_unused_port_or_die() : 0;
-
/* For coverage, test with and without dualstack sockets. */
- for (grpc_forbid_dualstack_sockets_for_testing = 0;
- grpc_forbid_dualstack_sockets_for_testing <= 1;
- grpc_forbid_dualstack_sockets_for_testing++) {
- /* :: and 0.0.0.0 are handled identically. */
- test_connect("::", "127.0.0.1", port, 1);
- test_connect("::", "::ffff:127.0.0.1", port, 1);
- test_connect("::", "localhost", port, 1);
- test_connect("0.0.0.0", "127.0.0.1", port, 1);
- test_connect("0.0.0.0", "::ffff:127.0.0.1", port, 1);
- test_connect("0.0.0.0", "localhost", port, 1);
- if (do_ipv6) {
- test_connect("::", "::1", port, 1);
- test_connect("0.0.0.0", "::1", port, 1);
- }
-
- /* These only work when the families agree. */
- test_connect("127.0.0.1", "127.0.0.1", port, 1);
- if (do_ipv6) {
- test_connect("::1", "::1", port, 1);
- test_connect("::1", "127.0.0.1", port, 0);
- test_connect("127.0.0.1", "::1", port, 0);
- }
+ for (grpc_forbid_dualstack_sockets_for_testing = 0;
+ grpc_forbid_dualstack_sockets_for_testing <= 1;
+ grpc_forbid_dualstack_sockets_for_testing++) {
+ /* :: and 0.0.0.0 are handled identically. */
+ test_connect("::", "127.0.0.1", 0, 1);
+ test_connect("::", "::ffff:127.0.0.1", 0, 1);
+ test_connect("::", "localhost", 0, 1);
+ test_connect("0.0.0.0", "127.0.0.1", 0, 1);
+ test_connect("0.0.0.0", "::ffff:127.0.0.1", 0, 1);
+ test_connect("0.0.0.0", "localhost", 0, 1);
+ if (do_ipv6) {
+ test_connect("::", "::1", 0, 1);
+ test_connect("0.0.0.0", "::1", 0, 1);
+ }
+
+ /* These only work when the families agree. */
+ test_connect("127.0.0.1", "127.0.0.1", 0, 1);
+ if (do_ipv6) {
+ test_connect("::1", "::1", 0, 1);
+ test_connect("::1", "127.0.0.1", 0, 0);
+ test_connect("127.0.0.1", "::1", 0, 0);
}
}