@@ -445,14 +445,8 @@ func (s) TestCircuitBreaking(t *testing.T) {
445445 if ctx .Err () != nil {
446446 t .Fatalf ("Context error: %v" , ctx .Err ())
447447 }
448- _ , err := client .FullDuplexCall (ctx )
449- switch {
450- case err == nil :
451- t .Fatalf ("client.FullDuplexCall(_) failed with unexpected error got: <nil>, want: %v" , err )
452- case status .Code (err ) == codes .Unavailable :
453- continue
454- default :
455- t .Errorf ("client.FullDuplexCall(_) failed with unexpected error = %v" , err )
448+ if _ , err := client .FullDuplexCall (ctx ); status .Code (err ) != codes .Unavailable {
449+ t .Fatalf ("client.FullDuplexCall() returned status %q, want %q" , status .Code (err ), codes .Unavailable )
456450 }
457451 }
458452
@@ -506,13 +500,12 @@ func (s) TestCircuitBreaking(t *testing.T) {
506500// the observed probability is within a certain error_tolerance of the expected
507501// probability (p).
508502func computeIdealNumRpcs (p , errorTolerance float64 ) uint64 {
509- numRpcs := uint64 (math .Ceil (p * (1 - p ) * 5.00 * 5.00 / errorTolerance / errorTolerance ))
510- return numRpcs
503+ return uint64 (math .Ceil (p * (1 - p ) * 5.00 * 5.00 / errorTolerance / errorTolerance ))
511504}
512505
513506// TestDropByCategory verifies that the balancer correctly drops the picks, and
514507// that the drops are reported.
515- func ( s ) TestDropByCategory (t * testing.T ) {
508+ func TestDropByCategory (t * testing.T ) {
516509 // Create an xDS management server that serves ADS and LRS requests.
517510 mgmtServer := e2e .StartManagementServer (t , e2e.ManagementServerOptions {SupportLoadReportingService : true })
518511
@@ -543,8 +536,8 @@ func (s) TestDropByCategory(t *testing.T) {
543536 server := stubserver .StartTestService (t , f )
544537 defer server .Stop ()
545538
546- // Configure xDS resources on the management server with drops configuration
547- // that drops one RPC for every 50 RPCs made.
539+ // Configure xDS resources on the management server with drops
540+ // configuration that drops one RPC for every 50 RPCs made.
548541 const (
549542 dropReason = "test-dropping-category"
550543 dropNumerator = 1
@@ -554,7 +547,7 @@ func (s) TestDropByCategory(t *testing.T) {
554547 )
555548 wantRPCDropRate := float64 (dropNumerator ) / float64 (dropDenominator )
556549 rpcCount := computeIdealNumRpcs (wantRPCDropRate , errorTolerance )
557- t .Logf ("Computed rpcCount: %d " , rpcCount )
550+ t .Logf ("About to send %d RPCs to test drop rate of %v " , rpcCount , wantRPCDropRate )
558551
559552 resources := e2e .DefaultClientResources (e2e.ResourceParams {
560553 DialTarget : serviceName ,
@@ -595,7 +588,8 @@ func (s) TestDropByCategory(t *testing.T) {
595588 }
596589 defer cc .Close ()
597590
598- // Ensure the gRPC channel is READY before issuing RPCs to get accurate drop count.
591+ // Ensure the gRPC channel is READY before issuing RPCs to get accurate
592+ // drop count.
599593 cc .Connect ()
600594 client := testgrpc .NewTestServiceClient (cc )
601595 testutils .AwaitState (ctx , t , cc , connectivity .Ready )
@@ -620,29 +614,37 @@ func (s) TestDropByCategory(t *testing.T) {
620614 t .Fatalf ("Failure when waiting for an LRS stream to be opened: %v" , err )
621615 }
622616
623- if _ , err = mgmtServer .LRSServer .LRSRequestChan .Receive (ctx ); err != nil {
624- t .Fatalf ("Failure waiting for initial LRS request: %v" , err )
625- }
626-
627617 resp := fakeserver.Response {
628618 Resp : & v3lrspb.LoadStatsResponse {
629- SendAllClusters : true ,
630- LoadReportingInterval : durationpb .New (time .Second ),
619+ Clusters : [] string { resources . Clusters [ 0 ]. Name } ,
620+ LoadReportingInterval : durationpb .New (50 * time .Millisecond ),
631621 },
632622 }
633623 mgmtServer .LRSServer .LRSResponseChan <- & resp
634624
635- select {
636- case req := <- mgmtServer .LRSServer .LRSRequestChan .C :
637- loadStats := req .(* fakeserver.Request ).Req .(* v3lrspb.LoadStatsRequest )
638- for _ , cs := range loadStats .ClusterStats {
625+ for {
626+ if ctx .Err () != nil {
627+ t .Fatalf ("Timeout when waiting for new loads to be seen on the server" )
628+ }
629+
630+ req , err := mgmtServer .LRSServer .LRSRequestChan .Receive (ctx )
631+ if err != nil {
632+ continue
633+ }
634+ loadStats := req .(* fakeserver.Request ).Req .(* v3lrspb.LoadStatsRequest ).ClusterStats
635+ if len (loadStats ) != 1 {
636+ continue
637+ }
638+ for _ , cs := range loadStats {
639+ if cs .ClusterName != resources .Clusters [0 ].Name {
640+ t .Fatalf ("Received stats for unexpected cluster got: %v, want: %v" , cs .ClusterName , resources .Clusters [0 ].Name )
641+ }
639642 gotRPCDropRate := float64 (cs .TotalDroppedRequests ) / float64 (rpcCount )
640- if math .Abs (gotRPCDropRate - wantRPCDropRate ) > errorTolerance {
641- t .Errorf ("Drop rate goes out of errortolerance got: %v, want: %v, totalDroppedRequest: %v, totalIssuesRequest: %v" , math .Abs (gotRPCDropRate - wantRPCDropRate ), errorTolerance , cs .TotalDroppedRequests , cs .UpstreamLocalityStats [0 ].TotalIssuedRequests )
643+ if ( math .Trunc ( math . Abs (gotRPCDropRate - wantRPCDropRate ) * 100 ) / 100 ) > errorTolerance {
644+ t .Errorf ("Drop rate goes out of errortolerance got: %v, want: %v, totalDroppedRequest: %v, totalIssuesRequest: %v" , ( math .Trunc ( math . Abs (gotRPCDropRate - wantRPCDropRate ) * 100 ) / 100 ), errorTolerance , cs .TotalDroppedRequests , cs .UpstreamLocalityStats [0 ].TotalIssuedRequests )
642645 }
643646 }
644- case <- ctx .Done ():
645- t .Fatalf ("Timeout while waiting for load report on LRS stream: %v" , ctx .Err ())
647+ break
646648 }
647649
648650 // Update the drop configuration to drop 1 out of every 40 RPCs,
@@ -674,7 +676,7 @@ func (s) TestDropByCategory(t *testing.T) {
674676
675677 wantRPCDropRate = float64 (dropNumerator2 ) / float64 (dropDenominator2 )
676678 rpcCount = computeIdealNumRpcs (wantRPCDropRate , errorTolerance )
677- t .Logf ("Computed rpcCount: %d " , rpcCount )
679+ t .Logf ("About to send %d RPCs to test drop rate of %v " , rpcCount , wantRPCDropRate )
678680
679681 for i := 0 ; i < int (rpcCount ); i ++ {
680682 if ctx .Err () != nil {
@@ -692,17 +694,35 @@ func (s) TestDropByCategory(t *testing.T) {
692694 }
693695 }
694696
695- select {
696- case req := <- mgmtServer .LRSServer .LRSRequestChan .C :
697- loadStats := req .(* fakeserver.Request ).Req .(* v3lrspb.LoadStatsRequest )
698- for _ , cs := range loadStats .ClusterStats {
699- gotRPCDropRate := float64 (cs .TotalDroppedRequests ) / float64 (rpcCount )
700- if math .Abs (gotRPCDropRate - wantRPCDropRate ) > errorTolerance {
701- t .Errorf ("Drop rate goes out of errortolerance got: %v, want: %v, totalDroppedRequest: %v, totalIssuesRequest: %v" , math .Abs (gotRPCDropRate - wantRPCDropRate ), errorTolerance , cs .TotalDroppedRequests , cs .UpstreamLocalityStats [0 ].TotalIssuedRequests )
697+ for {
698+ if ctx .Err () != nil {
699+ t .Fatalf ("Timeout when waiting for new loads to be seen on the server" )
700+ }
701+
702+ req , err := mgmtServer .LRSServer .LRSRequestChan .Receive (ctx )
703+ if err != nil {
704+ continue
705+ }
706+ loadStats := req .(* fakeserver.Request ).Req .(* v3lrspb.LoadStatsRequest ).ClusterStats
707+ if l := len (loadStats ); l != 1 {
708+ continue
709+ }
710+ for _ , cs := range loadStats {
711+ found := false
712+ for _ , dr := range cs .DroppedRequests {
713+ if dr .Category == dropReason2 {
714+ found = true
715+ gotRPCDropRate := float64 (dr .DroppedCount ) / float64 (rpcCount )
716+ if (math .Trunc (math .Abs (gotRPCDropRate - wantRPCDropRate )* 100 ) / 100 ) > errorTolerance {
717+ t .Errorf ("Drop rate goes out of errortolerance got: %v, want: %v, totalDroppedRequest: %v, totalIssuesRequest: %v" , (math .Trunc (math .Abs (gotRPCDropRate - wantRPCDropRate )* 100 ) / 100 ), errorTolerance , cs .TotalDroppedRequests , cs .UpstreamLocalityStats [0 ].TotalIssuedRequests )
718+ }
719+ }
720+ }
721+ if ! found {
722+ continue
702723 }
703724 }
704- case <- ctx .Done ():
705- t .Fatalf ("Timeout while waiting for load report on LRS stream: %v" , ctx .Err ())
725+ break
706726 }
707727}
708728
@@ -792,7 +812,7 @@ func (s) TestCircuitBreakingLogicalDNS(t *testing.T) {
792812 }
793813 }
794814
795- // Since we are at the max, new streams should fail. It's possible some are
815+ // Since we are at the max, new streams should fail. It's possible some are
796816 // allowed due to inherent raciness in the tracking, however.
797817 for i := 0 ; i < 100 ; i ++ {
798818 stream , err := client .FullDuplexCall (ctx )
0 commit comments