@@ -30,6 +30,7 @@ import (
30
30
31
31
"github.com/google/go-cmp/cmp"
32
32
"google.golang.org/grpc"
33
+ "google.golang.org/grpc/connectivity"
33
34
"google.golang.org/grpc/credentials/insecure"
34
35
"google.golang.org/grpc/internal"
35
36
"google.golang.org/grpc/internal/grpctest"
@@ -268,13 +269,12 @@ func (te *test) startServer(ts testgrpc.TestServiceServer) {
268
269
te .srvAddr = lis .Addr ().String ()
269
270
}
270
271
271
- func (te * test ) clientConn () * grpc.ClientConn {
272
+ func (te * test ) clientConn (ctx context. Context ) * grpc.ClientConn {
272
273
if te .cc != nil {
273
274
return te .cc
274
275
}
275
276
opts := []grpc.DialOption {
276
277
grpc .WithTransportCredentials (insecure .NewCredentials ()),
277
- grpc .WithBlock (),
278
278
grpc .WithUserAgent ("test/0.0.1" ),
279
279
}
280
280
if te .compress == "gzip" {
@@ -288,10 +288,12 @@ func (te *test) clientConn() *grpc.ClientConn {
288
288
}
289
289
290
290
var err error
291
- te .cc , err = grpc .Dial (te .srvAddr , opts ... )
291
+ te .cc , err = grpc .NewClient (te .srvAddr , opts ... )
292
292
if err != nil {
293
- te .t .Fatalf ("Dial (%q) = %v" , te .srvAddr , err )
293
+ te .t .Fatalf ("grpc.NewClient (%q) failed: %v" , te .srvAddr , err )
294
294
}
295
+ te .cc .Connect ()
296
+ testutils .AwaitState (ctx , te .t , te .cc , connectivity .Ready )
295
297
return te .cc
296
298
}
297
299
@@ -317,15 +319,15 @@ func (te *test) doUnaryCall(c *rpcConfig) (*testpb.SimpleRequest, *testpb.Simple
317
319
req * testpb.SimpleRequest
318
320
err error
319
321
)
320
- tc := testgrpc .NewTestServiceClient (te .clientConn ())
322
+ tCtx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
323
+ defer cancel ()
324
+ tc := testgrpc .NewTestServiceClient (te .clientConn (tCtx ))
321
325
if c .success {
322
326
req = & testpb.SimpleRequest {Payload : idToPayload (errorID + 1 )}
323
327
} else {
324
328
req = & testpb.SimpleRequest {Payload : idToPayload (errorID )}
325
329
}
326
330
327
- tCtx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
328
- defer cancel ()
329
331
resp , err = tc .UnaryCall (metadata .NewOutgoingContext (tCtx , testMetadata ), req , grpc .WaitForReady (! c .failfast ))
330
332
return req , resp , err
331
333
}
@@ -336,9 +338,9 @@ func (te *test) doFullDuplexCallRoundtrip(c *rpcConfig) ([]proto.Message, []prot
336
338
resps []proto.Message
337
339
err error
338
340
)
339
- tc := testgrpc .NewTestServiceClient (te .clientConn ())
340
341
tCtx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
341
342
defer cancel ()
343
+ tc := testgrpc .NewTestServiceClient (te .clientConn (tCtx ))
342
344
stream , err := tc .FullDuplexCall (metadata .NewOutgoingContext (tCtx , testMetadata ), grpc .WaitForReady (! c .failfast ))
343
345
if err != nil {
344
346
return reqs , resps , err
@@ -377,9 +379,9 @@ func (te *test) doClientStreamCall(c *rpcConfig) ([]proto.Message, *testpb.Strea
377
379
resp * testpb.StreamingInputCallResponse
378
380
err error
379
381
)
380
- tc := testgrpc .NewTestServiceClient (te .clientConn ())
381
382
tCtx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
382
383
defer cancel ()
384
+ tc := testgrpc .NewTestServiceClient (te .clientConn (tCtx ))
383
385
stream , err := tc .StreamingInputCall (metadata .NewOutgoingContext (tCtx , testMetadata ), grpc .WaitForReady (! c .failfast ))
384
386
if err != nil {
385
387
return reqs , resp , err
@@ -407,16 +409,15 @@ func (te *test) doServerStreamCall(c *rpcConfig) (*testpb.StreamingOutputCallReq
407
409
resps []proto.Message
408
410
err error
409
411
)
410
-
411
- tc := testgrpc .NewTestServiceClient (te .clientConn ())
412
+ tCtx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
413
+ defer cancel ()
414
+ tc := testgrpc .NewTestServiceClient (te .clientConn (tCtx ))
412
415
413
416
var startID int32
414
417
if ! c .success {
415
418
startID = errorID
416
419
}
417
420
req = & testpb.StreamingOutputCallRequest {Payload : idToPayload (startID )}
418
- tCtx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
419
- defer cancel ()
420
421
stream , err := tc .StreamingOutputCall (metadata .NewOutgoingContext (tCtx , testMetadata ), req , grpc .WaitForReady (! c .failfast ))
421
422
if err != nil {
422
423
return req , resps , err
0 commit comments