@@ -23,6 +23,7 @@ import (
2323 "encoding/json"
2424 "errors"
2525 "fmt"
26+ "slices"
2627 "strings"
2728 "sync"
2829 "testing"
@@ -1946,6 +1947,20 @@ func (s) TestPickFirstLeaf_HappyEyeballs_TF_AfterEndOfList(t *testing.T) {
19461947 if got , _ := tmr .Metric ("grpc.lb.pick_first.disconnections" ); got != 0 {
19471948 t .Errorf ("Unexpected data for metric %v, got: %v, want: %v" , "grpc.lb.pick_first.disconnections" , got , 0 )
19481949 }
1950+
1951+ if got , _ := tmr .Metric ("grpc.subchannel.connection_attempts_succeeded" ); got != 0 {
1952+ t .Errorf ("Unexpected data for metric %v, got: %v, want: %v" , "grpc.subchannel.connection_attempts_succeeded" , got , 0 )
1953+ }
1954+ if got , _ := tmr .Metric ("grpc.subchannel.connection_attempts_failed" ); got != 1 {
1955+ t .Errorf ("Unexpected data for metric %v, got: %v, want: %v" , "grpc.subchannel.connection_attempts_failed" , got , 1 )
1956+ }
1957+ expectedLabels := []string {"whatever:///test.server" , "" , "{region=\" \" , zone=\" \" , sub_zone=\" \" }" }
1958+ if detail , _ := tmr .MetricDetail ("grpc.subchannel.connection_attempts_failed" ); ! slices .Equal (detail .LabelVals , expectedLabels ) {
1959+ t .Errorf ("Unexpected label values for metric %v, got: %v, want %v" , "grpc.subchannel.connection_attempts_failed" , detail .LabelVals , expectedLabels )
1960+ }
1961+ if got , _ := tmr .Metric ("grpc.subchannel.disconnections" ); got != 0 {
1962+ t .Errorf ("Unexpected data for metric %v, got: %v, want: %v" , "grpc.subchannel.disconnections" , got , 0 )
1963+ }
19491964}
19501965
19511966// Test verifies that pickfirst attempts to connect to the second backend once
@@ -2006,6 +2021,27 @@ func (s) TestPickFirstLeaf_HappyEyeballs_TriggerConnectionDelay(t *testing.T) {
20062021 if got , _ := tmr .Metric ("grpc.lb.pick_first.disconnections" ); got != 0 {
20072022 t .Errorf ("Unexpected data for metric %v, got: %v, want: %v" , "grpc.lb.pick_first.disconnections" , got , 0 )
20082023 }
2024+
2025+ if got , _ := tmr .Metric ("grpc.subchannel.connection_attempts_succeeded" ); got != 1 {
2026+ t .Errorf ("Unexpected data for metric %v, got: %v, want: %v" , "grpc.subchannel.connection_attempts_succeeded" , got , 1 )
2027+ }
2028+ expectedLabels := []string {"whatever:///test.server" , "" , "{region=\" \" , zone=\" \" , sub_zone=\" \" }" }
2029+ if got , _ := tmr .MetricDetail ("grpc.subchannel.connection_attempts_succeeded" ); ! slices .Equal (got .LabelVals , expectedLabels ) {
2030+ t .Errorf ("Unexpected data for metric %v, got: %s, want: %s" , "grpc.subchannel.connection_attempts_succeeded" , got .LabelVals , expectedLabels )
2031+ }
2032+ if got , _ := tmr .Metric ("grpc.subchannel.connection_attempts_failed" ); got != 0 {
2033+ t .Errorf ("Unexpected data for metric %v, got: %v, want: %v" , "grpc.subchannel.connection_attempts_failed" , got , 0 )
2034+ }
2035+ if got , _ := tmr .Metric ("grpc.subchannel.disconnections" ); got != 0 {
2036+ t .Errorf ("Unexpected data for metric %v, got: %v, want: %v" , "grpc.subchannel.disconnections" , got , 0 )
2037+ }
2038+ if got , _ := tmr .Metric ("grpc.subchannel.open_connections" ); got != 1 {
2039+ t .Errorf ("Unexpected data for metric %v, got: %v, want: %v" , "grpc.subchannel.open_connections" , got , 1 )
2040+ }
2041+ expectedLabels = []string {"whatever:///test.server" , "" , "NoSecurity" , "{region=\" \" , zone=\" \" , sub_zone=\" \" }" }
2042+ if got , _ := tmr .MetricDetail ("grpc.subchannel.open_connections" ); ! slices .Equal (got .LabelVals , expectedLabels ) {
2043+ t .Errorf ("Unexpected data for metric %v, got: %s, want: %s" , "grpc.subchannel.open_connections" , got .LabelVals , expectedLabels )
2044+ }
20092045}
20102046
20112047// Test tests the pickfirst balancer by causing a SubConn to fail and then
@@ -2057,6 +2093,13 @@ func (s) TestPickFirstLeaf_HappyEyeballs_TF_ThenTimerFires(t *testing.T) {
20572093 if got , _ := tmr .Metric ("grpc.lb.pick_first.connection_attempts_failed" ); got != 1 {
20582094 t .Errorf ("Unexpected data for metric %v, got: %v, want: %v" , "grpc.lb.pick_first.connection_attempts_failed" , got , 1 )
20592095 }
2096+ if got , _ := tmr .Metric ("grpc.subchannel.connection_attempts_failed" ); got != 1 {
2097+ t .Errorf ("Unexpected data for metric %v, got: %v, want: %v" , "grpc.subchannel.connection_attempts_failed" , got , 1 )
2098+ }
2099+ expectedLabels := []string {"whatever:///test.server" , "" , "{region=\" \" , zone=\" \" , sub_zone=\" \" }" }
2100+ if got , _ := tmr .MetricDetail ("grpc.subchannel.connection_attempts_failed" ); ! slices .Equal (got .LabelVals , expectedLabels ) {
2101+ t .Errorf ("Unexpected data for metric %v, got: %s, want: %s" , "grpc.subchannel.connection_attempts_failed" , got .LabelVals , expectedLabels )
2102+ }
20602103 if holds [2 ].IsStarted () != false {
20612104 t .Fatalf ("Server %d with address %q contacted unexpectedly" , 2 , addrs [2 ])
20622105 }
@@ -2080,6 +2123,17 @@ func (s) TestPickFirstLeaf_HappyEyeballs_TF_ThenTimerFires(t *testing.T) {
20802123 if got , _ := tmr .Metric ("grpc.lb.pick_first.disconnections" ); got != 0 {
20812124 t .Errorf ("Unexpected data for metric %v, got: %v, want: %v" , "grpc.lb.pick_first.disconnections" , got , 0 )
20822125 }
2126+
2127+ if got , _ := tmr .Metric ("grpc.subchannel.connection_attempts_succeeded" ); got != 1 {
2128+ t .Errorf ("Unexpected data for metric %v, got: %v, want: %v" , "grpc.subchannel.connection_attempts_succeeded" , got , 1 )
2129+ }
2130+ expectedLabels = []string {"whatever:///test.server" , "" , "{region=\" \" , zone=\" \" , sub_zone=\" \" }" }
2131+ if got , _ := tmr .MetricDetail ("grpc.subchannel.connection_attempts_succeeded" ); ! slices .Equal (got .LabelVals , expectedLabels ) {
2132+ t .Errorf ("Unexpected data for metric %v, got: %s, want: %s" , "grpc.subchannel.connection_attempts_succeeded" , got .LabelVals , expectedLabels )
2133+ }
2134+ if got , _ := tmr .Metric ("grpc.subchannel.disconnections" ); got != 0 {
2135+ t .Errorf ("Unexpected data for metric %v, got: %v, want: %v" , "grpc.subchannel.disconnections" , got , 0 )
2136+ }
20832137}
20842138
20852139func (s ) TestPickFirstLeaf_InterleavingIPV4Preferred (t * testing.T ) {
0 commit comments