@@ -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 {
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
@@ -781,7 +785,6 @@ func runAndGetStats(t *testing.T, drop bool, runRPCs func(*grpc.ClientConn)) *rp
781
785
const (
782
786
countRPC = 40
783
787
failtosendURI = "failtosend"
784
- dropErrDesc = "request dropped by grpclb"
785
788
)
786
789
787
790
func TestGRPCLBStatsUnarySuccess (t * testing.T ) {
@@ -808,27 +811,22 @@ func TestGRPCLBStatsUnarySuccess(t *testing.T) {
808
811
809
812
func TestGRPCLBStatsUnaryDrop (t * testing.T ) {
810
813
defer leakcheck .Check (t )
811
- c := 0
812
814
stats := runAndGetStats (t , true , func (cc * grpc.ClientConn ) {
813
815
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
- }
816
+ // The first non-failfast RPC succeeds, all connections are up.
817
+ if _ , err := testC .EmptyCall (context .Background (), & testpb.Empty {}, grpc .WaitForReady (true )); err != nil {
818
+ t .Fatalf ("%v.EmptyCall(_, _) = _, %v, want _, <nil>" , testC , err )
821
819
}
822
- for i := 0 ; i < countRPC ; i ++ {
820
+ for i := 0 ; i < countRPC - 1 ; i ++ {
823
821
testC .EmptyCall (context .Background (), & testpb.Empty {})
824
822
}
825
823
})
826
824
827
825
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 ) },
826
+ numCallsStarted : int64 (countRPC ),
827
+ numCallsFinished : int64 (countRPC ),
828
+ numCallsFinishedKnownReceived : int64 (countRPC ) / 2 ,
829
+ numCallsDropped : map [string ]int64 {lbToken : int64 (countRPC ) / 2 },
832
830
}); err != nil {
833
831
t .Fatal (err )
834
832
}
@@ -895,27 +893,36 @@ func TestGRPCLBStatsStreamingSuccess(t *testing.T) {
895
893
896
894
func TestGRPCLBStatsStreamingDrop (t * testing.T ) {
897
895
defer leakcheck .Check (t )
898
- c := 0
899
896
stats := runAndGetStats (t , true , func (cc * grpc.ClientConn ) {
900
897
testC := testpb .NewTestServiceClient (cc )
898
+ // The first non-failfast RPC succeeds, all connections are up.
899
+ stream , err := testC .FullDuplexCall (context .Background (), grpc .WaitForReady (true ))
900
+ if err != nil {
901
+ t .Fatalf ("%v.FullDuplexCall(_, _) = _, %v, want _, <nil>" , testC , err )
902
+ }
901
903
for {
902
- c ++
903
- if _ , err := testC .EmptyCall (context .Background (), & testpb.Empty {}); err != nil {
904
- if strings .Contains (err .Error (), dropErrDesc ) {
905
- break
906
- }
904
+ if _ , err = stream .Recv (); err == io .EOF {
905
+ break
907
906
}
908
907
}
909
- for i := 0 ; i < countRPC ; i ++ {
910
- testC .FullDuplexCall (context .Background ())
908
+ for i := 0 ; i < countRPC - 1 ; i ++ {
909
+ stream , err = testC .FullDuplexCall (context .Background ())
910
+ if err == nil {
911
+ // Wait for stream to end if err is nil.
912
+ for {
913
+ if _ , err = stream .Recv (); err == io .EOF {
914
+ break
915
+ }
916
+ }
917
+ }
911
918
}
912
919
})
913
920
914
921
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 ) },
922
+ numCallsStarted : int64 (countRPC ),
923
+ numCallsFinished : int64 (countRPC ),
924
+ numCallsFinishedKnownReceived : int64 (countRPC ) / 2 ,
925
+ numCallsDropped : map [string ]int64 {lbToken : int64 (countRPC ) / 2 },
919
926
}); err != nil {
920
927
t .Fatal (err )
921
928
}
0 commit comments