Documentation ¶
Overview ¶
Package testutils provides utility types, for use in xds tests.
Index ¶
- Constants
- Variables
- func AvailableHostPort() (string, error)
- func IsRoundRobin(want []balancer.SubConn, f func() balancer.SubConn) error
- func LocalityIDToProto(l internal.LocalityID) *v2corepb.Locality
- func NewTestWRR() wrr.WRR
- type AddLocalityOptions
- type ClusterLoadAssignmentBuilder
- type TestClientConn
- func (tcc *TestClientConn) NewSubConn(a []resolver.Address, o balancer.NewSubConnOptions) (balancer.SubConn, error)
- func (tcc *TestClientConn) RemoveSubConn(sc balancer.SubConn)
- func (tcc *TestClientConn) ResolveNow(resolver.ResolveNowOptions)
- func (tcc *TestClientConn) Target() string
- func (tcc *TestClientConn) UpdateBalancerState(s connectivity.State, p balancer.Picker)
- func (tcc *TestClientConn) UpdateState(bs balancer.State)
- func (tcc *TestClientConn) WaitForErrPicker(ctx context.Context) error
- type TestConstBalancerBuilder
- type TestConstPicker
- type TestSubConn
Constants ¶
const TestSubConnsCount = 16
TestSubConnsCount is the number of TestSubConns initialized as part of package init.
Variables ¶
var EmptyNodeProtoV2 = &v2corepb.Node{}
EmptyNodeProtoV2 is a v2 Node proto with no fields set.
var EmptyNodeProtoV3 = &v3corepb.Node{}
EmptyNodeProtoV3 is a v3 Node proto with no fields set.
var ErrTestConstPicker = fmt.Errorf("const picker error")
ErrTestConstPicker is error returned by test const picker.
var TestSubConns []*TestSubConn
TestSubConns contains a list of SubConns to be used in tests.
Functions ¶
func AvailableHostPort ¶ added in v1.34.0
AvailableHostPort returns a local address to listen on. This will be of the form "host:port", where the host will be a literal IP address, and port must be a literal port number. If the host is a literal IPv6 address it will be enclosed in square brackets, as in "[2001:db8::1]:80.
This is useful for tests which need to call the Serve() method on xds.GRPCServer which needs to be passed an IP:Port to listen on, where the IP must be a literal IP and not localhost. This approach will work on support one or both of IPv4 or IPv6.
func IsRoundRobin ¶ added in v1.29.0
IsRoundRobin checks whether f's return value is roundrobin of elements from want. But it doesn't check for the order. Note that want can contain duplicate items, which makes it weight-round-robin.
Step 1. the return values of f should form a permutation of all elements in want, but not necessary in the same order. E.g. if want is {a,a,b}, the check fails if f returns:
- {a,a,a}: third a is returned before b
- {a,b,b}: second b is returned before the second a
If error is found in this step, the returned error contains only the first iteration until where it goes wrong.
Step 2. the return values of f should be repetitions of the same permutation. E.g. if want is {a,a,b}, the check failes if f returns:
- {a,b,a,b,a,a}: though it satisfies step 1, the second iteration is not repeating the first iteration.
If error is found in this step, the returned error contains the first iteration + the second iteration until where it goes wrong.
func LocalityIDToProto ¶ added in v1.31.0
func LocalityIDToProto(l internal.LocalityID) *v2corepb.Locality
LocalityIDToProto converts a LocalityID to its proto representation.
func NewTestWRR ¶ added in v1.29.0
NewTestWRR return a WRR for testing. It's deterministic instead of random.
Types ¶
type AddLocalityOptions ¶ added in v1.32.0
type AddLocalityOptions struct { Health []v2corepb.HealthStatus Weight []uint32 }
AddLocalityOptions contains options when adding locality to the builder.
type ClusterLoadAssignmentBuilder ¶ added in v1.32.0
type ClusterLoadAssignmentBuilder struct {
// contains filtered or unexported fields
}
ClusterLoadAssignmentBuilder builds a ClusterLoadAssignment, aka EDS response.
func NewClusterLoadAssignmentBuilder ¶ added in v1.32.0
func NewClusterLoadAssignmentBuilder(clusterName string, dropPercents []uint32) *ClusterLoadAssignmentBuilder
NewClusterLoadAssignmentBuilder creates a ClusterLoadAssignmentBuilder.
func (*ClusterLoadAssignmentBuilder) AddLocality ¶ added in v1.32.0
func (clab *ClusterLoadAssignmentBuilder) AddLocality(subzone string, weight uint32, priority uint32, addrsWithPort []string, opts *AddLocalityOptions)
AddLocality adds a locality to the builder.
func (*ClusterLoadAssignmentBuilder) Build ¶ added in v1.32.0
func (clab *ClusterLoadAssignmentBuilder) Build() *v2xdspb.ClusterLoadAssignment
Build builds ClusterLoadAssignment.
type TestClientConn ¶ added in v1.29.0
type TestClientConn struct { NewSubConnAddrsCh chan []resolver.Address // the last 10 []Address to create subconn. NewSubConnCh chan balancer.SubConn // the last 10 subconn created. RemoveSubConnCh chan balancer.SubConn // the last 10 subconn removed. NewPickerCh chan balancer.Picker // the last picker updated. NewStateCh chan connectivity.State // the last state. // contains filtered or unexported fields }
TestClientConn is a mock balancer.ClientConn used in tests.
func NewTestClientConn ¶ added in v1.29.0
func NewTestClientConn(t *testing.T) *TestClientConn
NewTestClientConn creates a TestClientConn.
func (*TestClientConn) NewSubConn ¶ added in v1.29.0
func (tcc *TestClientConn) NewSubConn(a []resolver.Address, o balancer.NewSubConnOptions) (balancer.SubConn, error)
NewSubConn creates a new SubConn.
func (*TestClientConn) RemoveSubConn ¶ added in v1.29.0
func (tcc *TestClientConn) RemoveSubConn(sc balancer.SubConn)
RemoveSubConn removes the SubConn.
func (*TestClientConn) ResolveNow ¶ added in v1.29.0
func (tcc *TestClientConn) ResolveNow(resolver.ResolveNowOptions)
ResolveNow panics.
func (*TestClientConn) Target ¶ added in v1.29.0
func (tcc *TestClientConn) Target() string
Target panics.
func (*TestClientConn) UpdateBalancerState ¶ added in v1.29.0
func (tcc *TestClientConn) UpdateBalancerState(s connectivity.State, p balancer.Picker)
UpdateBalancerState implements balancer.Balancer API. It will be removed when switching to the new balancer interface.
func (*TestClientConn) UpdateState ¶ added in v1.29.0
func (tcc *TestClientConn) UpdateState(bs balancer.State)
UpdateState updates connectivity state and picker.
func (*TestClientConn) WaitForErrPicker ¶ added in v1.34.0
func (tcc *TestClientConn) WaitForErrPicker(ctx context.Context) error
WaitForErrPicker waits until an error picker is pushed to this ClientConn. Returns error if the provided context expires or a non-error picker is pushed to the ClientConn.
type TestConstBalancerBuilder ¶ added in v1.29.0
type TestConstBalancerBuilder struct{}
TestConstBalancerBuilder is a balancer builder for tests.
func (*TestConstBalancerBuilder) Build ¶ added in v1.29.0
func (*TestConstBalancerBuilder) Build(cc balancer.ClientConn, opts balancer.BuildOptions) balancer.Balancer
Build builds a test const balancer.
func (*TestConstBalancerBuilder) Name ¶ added in v1.29.0
func (*TestConstBalancerBuilder) Name() string
Name returns test-const-balancer name.
type TestConstPicker ¶ added in v1.29.0
TestConstPicker is a const picker for tests.
func (*TestConstPicker) Pick ¶ added in v1.29.0
func (tcp *TestConstPicker) Pick(info balancer.PickInfo) (balancer.PickResult, error)
Pick returns the const SubConn or the error.
type TestSubConn ¶ added in v1.29.0
type TestSubConn struct {
// contains filtered or unexported fields
}
TestSubConn implements the SubConn interface, to be used in tests.
func (*TestSubConn) Connect ¶ added in v1.29.0
func (tsc *TestSubConn) Connect()
Connect is a no-op.
func (*TestSubConn) String ¶ added in v1.29.0
func (tsc *TestSubConn) String() string
String implements stringer to print human friendly error message.
func (*TestSubConn) UpdateAddresses ¶ added in v1.29.0
func (tsc *TestSubConn) UpdateAddresses([]resolver.Address)
UpdateAddresses panics.
Directories ¶
Path | Synopsis |
---|---|
Package fakeclient provides a fake implementation of an xDS client.
|
Package fakeclient provides a fake implementation of an xDS client. |
Package fakeserver provides a fake implementation of the management server.
|
Package fakeserver provides a fake implementation of the management server. |