@@ -744,14 +744,18 @@ func runAndGetStats(t *testing.T, drop bool, runRPCs func(*grpc.ClientConn)) *rp
744
744
t .Fatalf ("failed to create new load balancer: %v" , err )
745
745
}
746
746
defer cleanup ()
747
- tss .ls .sls <- & lbpb.ServerList {
748
- Servers : []* lbpb.Server {{
749
- IpAddress : tss .beIPs [0 ],
750
- Port : int32 (tss .bePorts [0 ]),
747
+ servers := []* lbpb.Server {{
748
+ IpAddress : tss .beIPs [0 ],
749
+ Port : int32 (tss .bePorts [0 ]),
750
+ LoadBalanceToken : lbToken ,
751
+ }}
752
+ if drop {
753
+ servers = append (servers , & lbpb.Server {IpAddress : tss .beIPs [0 ],
751
754
LoadBalanceToken : lbToken ,
752
755
Drop : drop ,
753
- }},
756
+ })
754
757
}
758
+ tss .ls .sls <- & lbpb.ServerList {Servers : servers }
755
759
tss .ls .statsDura = 100 * time .Millisecond
756
760
creds := serverNameCheckCreds {expected : beServerName }
757
761
@@ -808,27 +812,22 @@ func TestGRPCLBStatsUnarySuccess(t *testing.T) {
808
812
809
813
func TestGRPCLBStatsUnaryDrop (t * testing.T ) {
810
814
defer leakcheck .Check (t )
811
- c := 0
812
815
stats := runAndGetStats (t , true , func (cc * grpc.ClientConn ) {
813
816
testC := testpb .NewTestServiceClient (cc )
814
- for {
815
- c ++
816
- if _ , err := testC .EmptyCall (context .Background (), & testpb.Empty {}); err != nil {
817
- if strings .Contains (err .Error (), dropErrDesc ) {
818
- break
819
- }
820
- }
817
+ // The first non-failfast RPC succeeds, all connections are up.
818
+ if _ , err := testC .EmptyCall (context .Background (), & testpb.Empty {}, grpc .WaitForReady (true )); err != nil {
819
+ t .Fatalf ("%v.EmptyCall(_, _) = _, %v, want _, <nil>" , testC , err )
821
820
}
822
- for i := 0 ; i < countRPC ; i ++ {
821
+ for i := 0 ; i < countRPC - 1 ; i ++ {
823
822
testC .EmptyCall (context .Background (), & testpb.Empty {})
824
823
}
825
824
})
826
825
827
826
if err := checkStats (stats , & rpcStats {
828
- numCallsStarted : int64 (countRPC + c ),
829
- numCallsFinished : int64 (countRPC + c ),
830
- numCallsFinishedWithClientFailedToSend : int64 (c - 1 ) ,
831
- numCallsDropped : map [string ]int64 {lbToken : int64 (countRPC + 1 ) },
827
+ numCallsStarted : int64 (countRPC ),
828
+ numCallsFinished : int64 (countRPC ),
829
+ numCallsFinishedKnownReceived : int64 (countRPC ) / 2 ,
830
+ numCallsDropped : map [string ]int64 {lbToken : int64 (countRPC ) / 2 },
832
831
}); err != nil {
833
832
t .Fatal (err )
834
833
}
@@ -898,24 +897,34 @@ func TestGRPCLBStatsStreamingDrop(t *testing.T) {
898
897
c := 0
899
898
stats := runAndGetStats (t , true , func (cc * grpc.ClientConn ) {
900
899
testC := testpb .NewTestServiceClient (cc )
900
+ // The first non-failfast RPC succeeds, all connections are up.
901
+ stream , err := testC .FullDuplexCall (context .Background (), grpc .WaitForReady (true ))
902
+ if err != nil {
903
+ t .Fatalf ("%v.FullDuplexCall(_, _) = _, %v, want _, <nil>" , testC , err )
904
+ }
901
905
for {
902
- c ++
903
- if _ , err := testC .EmptyCall (context .Background (), & testpb.Empty {}); err != nil {
904
- if strings .Contains (err .Error (), dropErrDesc ) {
905
- break
906
- }
906
+ if _ , err = stream .Recv (); err == io .EOF {
907
+ break
907
908
}
908
909
}
909
- for i := 0 ; i < countRPC ; i ++ {
910
- testC .FullDuplexCall (context .Background ())
910
+ for i := 0 ; i < countRPC - 1 ; i ++ {
911
+ stream , err = testC .FullDuplexCall (context .Background ())
912
+ if err == nil {
913
+ // Wait for stream to end if err is nil.
914
+ for {
915
+ if _ , err = stream .Recv (); err == io .EOF {
916
+ break
917
+ }
918
+ }
919
+ }
911
920
}
912
921
})
913
922
914
923
if err := checkStats (stats , & rpcStats {
915
- numCallsStarted : int64 (countRPC + c ),
916
- numCallsFinished : int64 (countRPC + c ),
917
- numCallsFinishedWithClientFailedToSend : int64 (c - 1 ) ,
918
- numCallsDropped : map [string ]int64 {lbToken : int64 (countRPC + 1 ) },
924
+ numCallsStarted : int64 (countRPC + c ),
925
+ numCallsFinished : int64 (countRPC + c ),
926
+ numCallsFinishedKnownReceived : int64 (countRPC ) / 2 ,
927
+ numCallsDropped : map [string ]int64 {lbToken : int64 (countRPC ) / 2 },
919
928
}); err != nil {
920
929
t .Fatal (err )
921
930
}
0 commit comments