diff --git a/balancer/grpclb/grpclb_test.go b/balancer/grpclb/grpclb_test.go index 62dc947e0ee5..0bba53ac1469 100644 --- a/balancer/grpclb/grpclb_test.go +++ b/balancer/grpclb/grpclb_test.go @@ -460,7 +460,7 @@ func (s) TestGRPCLB_Basic(t *testing.T) { } cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...) if err != nil { - t.Fatalf("Failed to dial to the backend %v", err) + t.Fatalf("Failed to create a newclient to the backend %v", err) } defer cc.Close() @@ -517,7 +517,7 @@ func (s) TestGRPCLB_Weighted(t *testing.T) { } cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...) if err != nil { - t.Fatalf("Failed to dial to the backend %v", err) + t.Fatalf("Failed to create a newclient to the backend %v", err) } defer cc.Close() @@ -597,7 +597,7 @@ func (s) TestGRPCLB_DropRequest(t *testing.T) { } cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...) if err != nil { - t.Fatalf("Failed to dial to the backend %v", err) + t.Fatalf("Failed to create a newclient to the backend %v", err) } defer cc.Close() testC := testgrpc.NewTestServiceClient(cc) @@ -769,7 +769,7 @@ func (s) TestGRPCLB_BalancerDisconnects(t *testing.T) { } cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...) if err != nil { - t.Fatalf("Failed to dial to the backend %v", err) + t.Fatalf("Failed to create a newclient to the backend %v", err) } defer cc.Close() testC := testgrpc.NewTestServiceClient(cc) @@ -940,7 +940,7 @@ func (s) TestGRPCLB_ExplicitFallback(t *testing.T) { } cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...) if err != nil { - t.Fatalf("Failed to dial to the backend %v", err) + t.Fatalf("Failed to create a newclient to the backend %v", err) } defer cc.Close() testC := testgrpc.NewTestServiceClient(cc) @@ -1008,11 +1008,12 @@ func (s) TestGRPCLB_FallBackWithNoServerAddress(t *testing.T) { grpc.WithTransportCredentials(&serverNameCheckCreds{}), grpc.WithContextDialer(fakeNameDialer), } - cc, err := grpc.Dial(r.Scheme()+":///"+beServerName, dopts...) + cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...) if err != nil { - t.Fatalf("Failed to dial to the backend %v", err) + t.Fatalf("Failed to create a newclient to the backend %v", err) } defer cc.Close() + cc.Connect() testC := testgrpc.NewTestServiceClient(cc) ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) @@ -1102,10 +1103,11 @@ func (s) TestGRPCLB_PickFirst(t *testing.T) { grpc.WithTransportCredentials(&serverNameCheckCreds{}), grpc.WithContextDialer(fakeNameDialer), } - cc, err := grpc.Dial(r.Scheme()+":///"+beServerName, dopts...) + cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...) if err != nil { - t.Fatalf("Failed to dial to the backend %v", err) + t.Fatalf("Failed to create a newclient: %v", err) } + cc.Connect() defer cc.Close() // Push a service config with grpclb as the load balancing policy and @@ -1241,10 +1243,11 @@ func testGRPCLBEmptyServerList(t *testing.T, svcfg string) { grpc.WithTransportCredentials(&serverNameCheckCreds{}), grpc.WithContextDialer(fakeNameDialer), } - cc, err := grpc.DialContext(ctx, r.Scheme()+":///"+beServerName, dopts...) + cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...) if err != nil { - t.Fatalf("Failed to dial to the backend %v", err) + t.Fatalf("Failed to create a newclient to the backend %v", err) } + cc.Connect() defer cc.Close() testC := testgrpc.NewTestServiceClient(cc) @@ -1311,15 +1314,16 @@ func (s) TestGRPCLBWithTargetNameFieldInConfig(t *testing.T) { // Push the backend address to the remote balancer. tss.ls.sls <- sl - cc, err := grpc.Dial(r.Scheme()+":///"+beServerName, + cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, grpc.WithResolvers(r), grpc.WithTransportCredentials(&serverNameCheckCreds{}), grpc.WithContextDialer(fakeNameDialer), grpc.WithUserAgent(testUserAgent)) if err != nil { - t.Fatalf("Failed to dial to the backend %v", err) + t.Fatalf("Failed to create a newclient to the backend %v", err) } defer cc.Close() + cc.Connect() testC := testgrpc.NewTestServiceClient(cc) // Push a resolver update with grpclb configuration which does not contain the @@ -1418,15 +1422,14 @@ func runAndCheckStats(t *testing.T, drop bool, statsChan chan *lbpb.ClientStats, tss.ls.statsDura = 100 * time.Millisecond creds := serverNameCheckCreds{} - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - cc, err := grpc.DialContext(ctx, r.Scheme()+":///"+beServerName, grpc.WithResolvers(r), + cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, grpc.WithResolvers(r), grpc.WithTransportCredentials(&creds), grpc.WithPerRPCCredentials(failPreRPCCred{}), grpc.WithContextDialer(fakeNameDialer)) if err != nil { - t.Fatalf("Failed to dial to the backend %v", err) + t.Fatalf("Failed to create a newclient to the backend %v", err) } + cc.Connect() defer cc.Close() rstate := resolver.State{ServiceConfig: r.CC.ParseServiceConfig(grpclbConfig)} diff --git a/balancer/rls/picker_test.go b/balancer/rls/picker_test.go index cb08c433f9e8..a0bdbc827921 100644 --- a/balancer/rls/picker_test.go +++ b/balancer/rls/picker_test.go @@ -267,9 +267,9 @@ func (s) Test_RLSDefaultTargetPicksMetric(t *testing.T) { r := startManualResolverWithConfig(t, rlsConfig) tmr := stats.NewTestMetricsRecorder() - cc, err := grpc.Dial(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithStatsHandler(tmr)) + cc, err := grpc.NewClient(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithStatsHandler(tmr)) if err != nil { - t.Fatalf("grpc.Dial() failed: %v", err) + t.Fatalf("grpc.NewClient() failed: %v", err) } defer cc.Close() @@ -314,9 +314,9 @@ func (s) Test_RLSTargetPicksMetric(t *testing.T) { tmr := stats.NewTestMetricsRecorder() // Dial the backend. - cc, err := grpc.Dial(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithStatsHandler(tmr)) + cc, err := grpc.NewClient(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithStatsHandler(tmr)) if err != nil { - t.Fatalf("grpc.Dial() failed: %v", err) + t.Fatalf("grpc.NewClient() failed: %v", err) } defer cc.Close() @@ -352,9 +352,9 @@ func (s) Test_RLSFailedPicksMetric(t *testing.T) { tmr := stats.NewTestMetricsRecorder() // Dial the backend. - cc, err := grpc.Dial(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithStatsHandler(tmr)) + cc, err := grpc.NewClient(r.Scheme()+":///", grpc.WithResolvers(r), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithStatsHandler(tmr)) if err != nil { - t.Fatalf("grpc.Dial() failed: %v", err) + t.Fatalf("grpc.NewClient() failed: %v", err) } defer cc.Close() diff --git a/resolver_balancer_ext_test.go b/resolver_balancer_ext_test.go index 417a5781ef80..75fac51a66db 100644 --- a/resolver_balancer_ext_test.go +++ b/resolver_balancer_ext_test.go @@ -66,11 +66,12 @@ func (s) TestResolverBalancerInteraction(t *testing.T) { rb.ResolveNowCallback = func(resolver.ResolveNowOptions) { close(rnCh) } resolver.Register(rb) - cc, err := grpc.Dial(name+":///", grpc.WithTransportCredentials(insecure.NewCredentials())) + cc, err := grpc.NewClient(name+":///", grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { - t.Fatalf("grpc.Dial error: %v", err) + t.Fatalf("grpc.NewClient error: %v", err) } defer cc.Close() + cc.Connect() select { case <-rnCh: case <-time.After(defaultTestTimeout): @@ -109,11 +110,12 @@ func (s) TestResolverBuildFailure(t *testing.T) { resolver.Register(&resolverBuilderWithErr{errCh: resErrCh, scheme: name}) resErrCh <- nil - cc, err := grpc.Dial(name+":///", grpc.WithTransportCredentials(insecure.NewCredentials())) + cc, err := grpc.NewClient(name+":///", grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { - t.Fatalf("grpc.Dial error: %v", err) + t.Fatalf("grpc.NewClient error: %v", err) } defer cc.Close() + cc.Connect() enterIdle(cc) const errStr = "test error from resolver builder" t.Log("pushing res err") diff --git a/test/creds_test.go b/test/creds_test.go index ff3818e0ad54..00702fd73bfd 100644 --- a/test/creds_test.go +++ b/test/creds_test.go @@ -236,9 +236,9 @@ func (s) TestFailFastRPCErrorOnBadCertificates(t *testing.T) { opts := []grpc.DialOption{grpc.WithTransportCredentials(clientAlwaysFailCred{})} ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) defer cancel() - cc, err := grpc.DialContext(ctx, te.srvAddr, opts...) + cc, err := grpc.NewClient(te.srvAddr, opts...) if err != nil { - t.Fatalf("Dial(_) = %v, want %v", err, nil) + t.Fatalf("NewClient(_) = %v, want %v", err, nil) } defer cc.Close() @@ -262,16 +262,14 @@ func (s) TestWaitForReadyRPCErrorOnBadCertificates(t *testing.T) { defer te.tearDown() opts := []grpc.DialOption{grpc.WithTransportCredentials(clientAlwaysFailCred{})} - ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) - defer cancel() - cc, err := grpc.DialContext(ctx, te.srvAddr, opts...) + cc, err := grpc.NewClient(te.srvAddr, opts...) if err != nil { - t.Fatalf("Dial(_) = %v, want %v", err, nil) + t.Fatalf("NewClient(_) = %v, want %v", err, nil) } defer cc.Close() tc := testgrpc.NewTestServiceClient(cc) - ctx, cancel = context.WithTimeout(context.Background(), defaultTestShortTimeout) + ctx, cancel := context.WithTimeout(context.Background(), defaultTestShortTimeout) defer cancel() if _, err = tc.EmptyCall(ctx, &testpb.Empty{}, grpc.WaitForReady(true)); !strings.Contains(err.Error(), clientAlwaysFailCredErrorMsg) { t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want err.Error() contains %q", err, clientAlwaysFailCredErrorMsg) @@ -437,10 +435,11 @@ func (s) TestCredsHandshakeAuthority(t *testing.T) { r := manual.NewBuilderWithScheme("whatever") - cc, err := grpc.Dial(r.Scheme()+":///"+testAuthority, grpc.WithTransportCredentials(cred), grpc.WithResolvers(r)) + cc, err := grpc.NewClient(r.Scheme()+":///"+testAuthority, grpc.WithTransportCredentials(cred), grpc.WithResolvers(r)) if err != nil { - t.Fatalf("grpc.Dial(%q) = %v", lis.Addr().String(), err) + t.Fatalf("grpc.NewClient(%q) = %v", lis.Addr().String(), err) } + cc.Connect() defer cc.Close() r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: lis.Addr().String()}}}) @@ -469,10 +468,11 @@ func (s) TestCredsHandshakeServerNameAuthority(t *testing.T) { r := manual.NewBuilderWithScheme("whatever") - cc, err := grpc.Dial(r.Scheme()+":///"+testAuthority, grpc.WithTransportCredentials(cred), grpc.WithResolvers(r)) + cc, err := grpc.NewClient(r.Scheme()+":///"+testAuthority, grpc.WithTransportCredentials(cred), grpc.WithResolvers(r)) if err != nil { - t.Fatalf("grpc.Dial(%q) = %v", lis.Addr().String(), err) + t.Fatalf("grpc.NewClient(%q) = %v", lis.Addr().String(), err) } + cc.Connect() defer cc.Close() r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: lis.Addr().String(), ServerName: testServerName}}}) @@ -524,10 +524,11 @@ func (s) TestServerCredsDispatch(t *testing.T) { go s.Serve(lis) defer s.Stop() - cc, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(cred)) + cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(cred)) if err != nil { - t.Fatalf("grpc.Dial(%q) = %v", lis.Addr().String(), err) + t.Fatalf("grpc.NewClient(%q) = %v", lis.Addr().String(), err) } + cc.Connect() defer cc.Close() rawConn := cred.getRawConn() diff --git a/test/end2end_test.go b/test/end2end_test.go index 2238f8f12422..6ea4670af1aa 100644 --- a/test/end2end_test.go +++ b/test/end2end_test.go @@ -609,7 +609,7 @@ func (te *test) listenAndServe(ts testgrpc.TestServiceServer, listen func(networ if te.serverInitialConnWindowSize > 0 { sopts = append(sopts, grpc.InitialConnWindowSize(te.serverInitialConnWindowSize)) } - la := "localhost:0" + la := "[::]:0" switch te.e.network { case "unix": la = "/tmp/testsock" + fmt.Sprintf("%d", time.Now().UnixNano())