Skip to content

Commit 8a2c220

Browse files
authored
cdsbalancer: test cleanup part 2/N (#6554)
1 parent 7f66074 commit 8a2c220

File tree

4 files changed

+610
-847
lines changed

4 files changed

+610
-847
lines changed

internal/credentials/xds/handshake_info.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,26 @@ func init() {
4343
// the Attributes field of resolver.Address.
4444
type handshakeAttrKey struct{}
4545

46-
// Equal reports whether the handshake info structs are identical (have the
47-
// same pointer). This is sufficient as all subconns from one CDS balancer use
48-
// the same one.
49-
func (hi *HandshakeInfo) Equal(o any) bool {
50-
oh, ok := o.(*HandshakeInfo)
51-
return ok && oh == hi
46+
// Equal reports whether the handshake info structs are identical.
47+
func (hi *HandshakeInfo) Equal(other *HandshakeInfo) bool {
48+
if hi == nil && other == nil {
49+
return true
50+
}
51+
if hi == nil || other == nil {
52+
return false
53+
}
54+
if hi.rootProvider != other.rootProvider ||
55+
hi.identityProvider != other.identityProvider ||
56+
hi.requireClientCert != other.requireClientCert ||
57+
len(hi.sanMatchers) != len(other.sanMatchers) {
58+
return false
59+
}
60+
for i := range hi.sanMatchers {
61+
if !hi.sanMatchers[i].Equal(other.sanMatchers[i]) {
62+
return false
63+
}
64+
}
65+
return true
5266
}
5367

5468
// SetHandshakeInfo returns a copy of addr in which the Attributes field is

internal/stubserver/stubserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func parseCfg(r *manual.Resolver, s string) *serviceconfig.ParseResult {
216216
// StartTestService spins up a stub server exposing the TestService on a local
217217
// port. If the passed in server is nil, a stub server that implements only the
218218
// EmptyCall and UnaryCall RPCs is started.
219-
func StartTestService(t *testing.T, server *StubServer) *StubServer {
219+
func StartTestService(t *testing.T, server *StubServer, sopts ...grpc.ServerOption) *StubServer {
220220
if server == nil {
221221
server = &StubServer{
222222
EmptyCallF: func(context.Context, *testpb.Empty) (*testpb.Empty, error) { return &testpb.Empty{}, nil },
@@ -225,7 +225,7 @@ func StartTestService(t *testing.T, server *StubServer) *StubServer {
225225
},
226226
}
227227
}
228-
server.StartServer()
228+
server.StartServer(sopts...)
229229

230230
t.Logf("Started test service backend at %q", server.Address)
231231
return server

0 commit comments

Comments
 (0)