Skip to content

Commit

Permalink
cdsbalancer: test cleanup part 2/N (#6554)
Browse files Browse the repository at this point in the history
  • Loading branch information
easwars authored Aug 18, 2023
1 parent 7f66074 commit 8a2c220
Show file tree
Hide file tree
Showing 4 changed files with 610 additions and 847 deletions.
26 changes: 20 additions & 6 deletions internal/credentials/xds/handshake_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,26 @@ func init() {
// the Attributes field of resolver.Address.
type handshakeAttrKey struct{}

// Equal reports whether the handshake info structs are identical (have the
// same pointer). This is sufficient as all subconns from one CDS balancer use
// the same one.
func (hi *HandshakeInfo) Equal(o any) bool {
oh, ok := o.(*HandshakeInfo)
return ok && oh == hi
// Equal reports whether the handshake info structs are identical.
func (hi *HandshakeInfo) Equal(other *HandshakeInfo) bool {
if hi == nil && other == nil {
return true
}
if hi == nil || other == nil {
return false
}
if hi.rootProvider != other.rootProvider ||
hi.identityProvider != other.identityProvider ||
hi.requireClientCert != other.requireClientCert ||
len(hi.sanMatchers) != len(other.sanMatchers) {
return false
}
for i := range hi.sanMatchers {
if !hi.sanMatchers[i].Equal(other.sanMatchers[i]) {
return false
}
}
return true
}

// SetHandshakeInfo returns a copy of addr in which the Attributes field is
Expand Down
4 changes: 2 additions & 2 deletions internal/stubserver/stubserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func parseCfg(r *manual.Resolver, s string) *serviceconfig.ParseResult {
// StartTestService spins up a stub server exposing the TestService on a local
// port. If the passed in server is nil, a stub server that implements only the
// EmptyCall and UnaryCall RPCs is started.
func StartTestService(t *testing.T, server *StubServer) *StubServer {
func StartTestService(t *testing.T, server *StubServer, sopts ...grpc.ServerOption) *StubServer {
if server == nil {
server = &StubServer{
EmptyCallF: func(context.Context, *testpb.Empty) (*testpb.Empty, error) { return &testpb.Empty{}, nil },
Expand All @@ -225,7 +225,7 @@ func StartTestService(t *testing.T, server *StubServer) *StubServer {
},
}
}
server.StartServer()
server.StartServer(sopts...)

t.Logf("Started test service backend at %q", server.Address)
return server
Expand Down
Loading

0 comments on commit 8a2c220

Please sign in to comment.