소스 검색

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.
David Klempner 10 년 전
부모
커밋
57c0061d78
1개의 변경된 파일25개의 추가작업 그리고 26개의 파일을 삭제
  1. 25 26
      test/core/end2end/dualstack_socket_test.c

+ 25 - 26
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);
     }
   }