@@ -848,9 +848,11 @@ func testFailFast(t *testing.T, e env) {
848
848
te .srv .Stop ()
849
849
// Loop until the server teardown is propagated to the client.
850
850
for {
851
- if _ , err := tc .EmptyCall (context .Background (), & testpb.Empty {}); grpc .Code (err ) == codes .Unavailable {
851
+ _ , err := tc .EmptyCall (context .Background (), & testpb.Empty {})
852
+ if grpc .Code (err ) == codes .Unavailable {
852
853
break
853
854
}
855
+ fmt .Printf ("%v.EmptyCall(_, _) = _, %v" , tc , err )
854
856
time .Sleep (10 * time .Millisecond )
855
857
}
856
858
// The client keeps reconnecting and ongoing fail-fast RPCs should fail with code.Unavailable.
@@ -2462,6 +2464,54 @@ func TestNonFailFastRPCSucceedOnTimeoutCreds(t *testing.T) {
2462
2464
}
2463
2465
}
2464
2466
2467
+ type serverDispatchCred struct {
2468
+ ready chan struct {}
2469
+ rawConn net.Conn
2470
+ }
2471
+
2472
+ func newServerDispatchCred () * serverDispatchCred {
2473
+ return & serverDispatchCred {
2474
+ ready : make (chan struct {}),
2475
+ }
2476
+ }
2477
+ func (c * serverDispatchCred ) ClientHandshake (ctx context.Context , addr string , rawConn net.Conn ) (net.Conn , credentials.AuthInfo , error ) {
2478
+ return rawConn , nil , nil
2479
+ }
2480
+ func (c * serverDispatchCred ) ServerHandshake (rawConn net.Conn ) (net.Conn , credentials.AuthInfo , error ) {
2481
+ c .rawConn = rawConn
2482
+ close (c .ready )
2483
+ return nil , nil , credentials .ErrConnDispatched
2484
+ }
2485
+ func (c * serverDispatchCred ) Info () credentials.ProtocolInfo {
2486
+ return credentials.ProtocolInfo {}
2487
+ }
2488
+ func (c * serverDispatchCred ) getRawConn () net.Conn {
2489
+ <- c .ready
2490
+ return c .rawConn
2491
+ }
2492
+
2493
+ func TestServerCredsDispatch (t * testing.T ) {
2494
+ lis , err := net .Listen ("tcp" , ":0" )
2495
+ if err != nil {
2496
+ t .Fatalf ("Failed to listen: %v" , err )
2497
+ }
2498
+ cred := newServerDispatchCred ()
2499
+ s := grpc .NewServer (grpc .Creds (cred ))
2500
+ go s .Serve (lis )
2501
+ defer s .Stop ()
2502
+
2503
+ cc , err := grpc .Dial (lis .Addr ().String (), grpc .WithTransportCredentials (cred ))
2504
+ if err != nil {
2505
+ t .Fatalf ("grpc.Dial(%q) = %v" , lis .Addr ().String (), err )
2506
+ }
2507
+ defer cc .Close ()
2508
+
2509
+ // Check rawConn is not closed.
2510
+ if n , err := cred .getRawConn ().Write ([]byte {0 }); n <= 0 || err != nil {
2511
+ t .Errorf ("Read() = %v, %v; want n>0, <nil>" , n , err )
2512
+ }
2513
+ }
2514
+
2465
2515
// interestingGoroutines returns all goroutines we care about for the purpose
2466
2516
// of leak checking. It excludes testing or runtime ones.
2467
2517
func interestingGoroutines () (gs []string ) {
0 commit comments