Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Remove fake petiole in health tests #8082

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 12 additions & 54 deletions test/healthcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/balancer/pickfirst"
"google.golang.org/grpc/balancer/pickfirst/pickfirstleaf"
"google.golang.org/grpc/balancer/roundrobin"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/health"
"google.golang.org/grpc/internal"
"google.golang.org/grpc/internal/balancer/stub"
"google.golang.org/grpc/internal/channelz"
"google.golang.org/grpc/internal/envconfig"
"google.golang.org/grpc/internal/grpctest"
"google.golang.org/grpc/internal/testutils"
"google.golang.org/grpc/resolver"
Expand All @@ -51,47 +50,6 @@ import (
testpb "google.golang.org/grpc/interop/grpc_testing"
)

const healthCheckingPetiolePolicyName = "health_checking_petiole_policy"

var (
// healthCheckTestPolicyName is the LB policy used for testing the health check
// service.
healthCheckTestPolicyName = "round_robin"
)

func init() {
balancer.Register(&healthCheckingPetiolePolicyBuilder{})
// Till dualstack changes are not implemented and round_robin doesn't
// delegate to pickfirst, test a fake petiole policy that delegates to
// the new pickfirst balancer.
// TODO: https://github.com/grpc/grpc-go/issues/7906 - Remove the fake
// petiole policy one round robin starts delegating to pickfirst.
if envconfig.NewPickFirstEnabled {
healthCheckTestPolicyName = healthCheckingPetiolePolicyName
}
}

type healthCheckingPetiolePolicyBuilder struct{}

func (bb *healthCheckingPetiolePolicyBuilder) Build(cc balancer.ClientConn, opts balancer.BuildOptions) balancer.Balancer {
return &healthCheckingPetiolePolicy{
Balancer: balancer.Get(pickfirstleaf.Name).Build(cc, opts),
}
}

func (bb *healthCheckingPetiolePolicyBuilder) Name() string {
return healthCheckingPetiolePolicyName
}

func (b *healthCheckingPetiolePolicy) UpdateClientConnState(state balancer.ClientConnState) error {
state.ResolverState = pickfirstleaf.EnableHealthListener(state.ResolverState)
return b.Balancer.UpdateClientConnState(state)
}

type healthCheckingPetiolePolicy struct {
balancer.Balancer
}

func newTestHealthServer() *testHealthServer {
return newTestHealthServerWithWatchFunc(defaultWatchFunc)
}
Expand Down Expand Up @@ -312,7 +270,7 @@ func (s) TestHealthCheckHealthServerNotRegistered(t *testing.T) {
"serviceName": "foo"
},
"loadBalancingConfig": [{"%s":{}}]
}`, healthCheckTestPolicyName))})
}`, roundrobin.Name))})

ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
Expand All @@ -339,7 +297,7 @@ func (s) TestHealthCheckWithGoAway(t *testing.T) {
"serviceName": "foo"
},
"loadBalancingConfig": [{"%s":{}}]
}`, healthCheckTestPolicyName))})
}`, roundrobin.Name))})

ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
Expand Down Expand Up @@ -417,7 +375,7 @@ func (s) TestHealthCheckWithConnClose(t *testing.T) {
"serviceName": "foo"
},
"loadBalancingConfig": [{"%s":{}}]
}`, healthCheckTestPolicyName))})
}`, roundrobin.Name))})

ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
Expand Down Expand Up @@ -465,7 +423,7 @@ func (s) TestHealthCheckWithAddrConnDrain(t *testing.T) {
"serviceName": "foo"
},
"loadBalancingConfig": [{"%s":{}}]
}`, healthCheckTestPolicyName))
}`, roundrobin.Name))
r.UpdateState(resolver.State{
Addresses: []resolver.Address{{Addr: lis.Addr().String()}},
ServiceConfig: sc,
Expand Down Expand Up @@ -547,7 +505,7 @@ func (s) TestHealthCheckWithClientConnClose(t *testing.T) {
"serviceName": "foo"
},
"loadBalancingConfig": [{"%s":{}}]
}`, healthCheckTestPolicyName)))})
}`, roundrobin.Name)))})

ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
Expand Down Expand Up @@ -614,7 +572,7 @@ func (s) TestHealthCheckWithoutSetConnectivityStateCalledAddrConnShutDown(t *tes
"serviceName": "delay"
},
"loadBalancingConfig": [{"%s":{}}]
}`, healthCheckTestPolicyName))
}`, roundrobin.Name))
r.UpdateState(resolver.State{
Addresses: []resolver.Address{{Addr: lis.Addr().String()}},
ServiceConfig: sc,
Expand Down Expand Up @@ -679,7 +637,7 @@ func (s) TestHealthCheckWithoutSetConnectivityStateCalled(t *testing.T) {
"serviceName": "delay"
},
"loadBalancingConfig": [{"%s":{}}]
}`, healthCheckTestPolicyName))})
}`, roundrobin.Name))})

select {
case <-hcExitChan:
Expand Down Expand Up @@ -717,7 +675,7 @@ func testHealthCheckDisableWithDialOption(t *testing.T, addr string) {
"serviceName": "foo"
},
"loadBalancingConfig": [{"%s":{}}]
}`, healthCheckTestPolicyName))})
}`, roundrobin.Name))})

ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
Expand Down Expand Up @@ -823,7 +781,7 @@ func (s) TestHealthCheckChannelzCountingCallSuccess(t *testing.T) {
"serviceName": "channelzSuccess"
},
"loadBalancingConfig": [{"%s":{}}]
}`, healthCheckTestPolicyName))})
}`, roundrobin.Name))})

if err := verifyResultWithDelay(func() (bool, error) {
cm, _ := channelz.GetTopChannels(0, 0)
Expand Down Expand Up @@ -872,7 +830,7 @@ func (s) TestHealthCheckChannelzCountingCallFailure(t *testing.T) {
"serviceName": "channelzFailure"
},
"loadBalancingConfig": [{"%s":{}}]
}`, healthCheckTestPolicyName))})
}`, roundrobin.Name))})

if err := verifyResultWithDelay(func() (bool, error) {
cm, _ := channelz.GetTopChannels(0, 0)
Expand Down Expand Up @@ -985,7 +943,7 @@ func (s) TestHealthCheckFailure(t *testing.T) {
name: "tcp-tls",
network: "tcp",
security: "tls",
balancer: healthCheckTestPolicyName,
balancer: roundrobin.Name,
}
te := newTest(t, e)
te.declareLogNoise(
Expand Down