testutils

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package testutils provides utility types, for use in xds tests.

Index

Constants

View Source
const (
	// DefaultChanRecvTimeout is the default timeout for receive operations on the
	// underlying channel.
	DefaultChanRecvTimeout = 1 * time.Second
	// DefaultChanBufferSize is the default buffer size of the underlying channel.
	DefaultChanBufferSize = 1
)

Variables

View Source
var ErrRecvTimeout = errors.New("timed out when waiting for value on channel")

ErrRecvTimeout is an error to indicate that a receive operation on the channel timed out.

View Source
var ErrTestConstPicker = fmt.Errorf("const picker error")

ErrTestConstPicker is error returned by test const picker.

View Source
var TestSubConns []*TestSubConn

TestSubConns contains a list of SubConns to be used in tests.

Functions

func IsRoundRobin

func IsRoundRobin(want []balancer.SubConn, f func() balancer.SubConn) error

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 NewTestWRR

func NewTestWRR() wrr.WRR

NewTestWRR return a WRR for testing. It's deterministic instead random.

Types

type Channel

type Channel struct {
	// contains filtered or unexported fields
}

Channel wraps a generic channel and provides a timed receive operation.

func NewChannel

func NewChannel() *Channel

NewChannel returns a new Channel.

func NewChannelWithSize

func NewChannelWithSize(bufSize int) *Channel

NewChannelWithSize returns a new Channel with a buffer of bufSize.

func (*Channel) Receive

func (cwt *Channel) Receive() (interface{}, error)

Receive returns the value received on the underlying channel, or ErrRecvTimeout if DefaultChanRecvTimeout amount of time elapses.

func (*Channel) Send

func (cwt *Channel) Send(value interface{})

Send sends value on the underlying channel.

func (*Channel) TimedReceive

func (cwt *Channel) TimedReceive(timeout time.Duration) (interface{}, error)

TimedReceive returns the value received on the underlying channel, or ErrRecvTimeout if timeout amount of time elapsed.

type TestClientConn

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.V2Picker  // 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

func NewTestClientConn(t *testing.T) *TestClientConn

NewTestClientConn creates a TestClientConn.

func (*TestClientConn) NewSubConn

NewSubConn creates a new SubConn.

func (*TestClientConn) RemoveSubConn

func (tcc *TestClientConn) RemoveSubConn(sc balancer.SubConn)

RemoveSubConn removes the SubConn.

func (*TestClientConn) ResolveNow

func (tcc *TestClientConn) ResolveNow(resolver.ResolveNowOptions)

ResolveNow panics.

func (*TestClientConn) Target

func (tcc *TestClientConn) Target() string

Target panics.

func (*TestClientConn) UpdateBalancerState

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

func (tcc *TestClientConn) UpdateState(bs balancer.State)

UpdateState updates connectivity state and picker.

type TestConstBalancerBuilder

type TestConstBalancerBuilder struct{}

TestConstBalancerBuilder is a balancer builder for tests.

func (*TestConstBalancerBuilder) Build

Build builds a test const balancer.

func (*TestConstBalancerBuilder) Name

Name returns test-const-balancer name.

type TestConstPicker

type TestConstPicker struct {
	Err error
	SC  balancer.SubConn
}

TestConstPicker is a const picker for tests.

func (*TestConstPicker) Pick

Pick returns the const SubConn or the error.

type TestLoadStore

type TestLoadStore struct {
	CallsStarted []internal.Locality
	CallsEnded   []internal.Locality
	CallsCost    []TestServerLoad
}

TestLoadStore is a load store to be used in tests.

func NewTestLoadStore

func NewTestLoadStore() *TestLoadStore

NewTestLoadStore creates a new TestLoadStore.

func (*TestLoadStore) CallDropped

func (*TestLoadStore) CallDropped(category string)

CallDropped records a call dropped.

func (*TestLoadStore) CallFinished

func (tls *TestLoadStore) CallFinished(l internal.Locality, err error)

CallFinished records a call finished.

func (*TestLoadStore) CallServerLoad

func (tls *TestLoadStore) CallServerLoad(l internal.Locality, name string, d float64)

CallServerLoad records a call server load.

func (*TestLoadStore) CallStarted

func (tls *TestLoadStore) CallStarted(l internal.Locality)

CallStarted records a call started.

func (*TestLoadStore) ReportTo

func (*TestLoadStore) ReportTo(ctx context.Context, cc *grpc.ClientConn, clusterName string, node *envoy_api_v2_core.Node)

ReportTo panics.

type TestServerLoad

type TestServerLoad struct {
	Name string
	D    float64
}

TestServerLoad is testing Load for testing LRS.

type TestSubConn

type TestSubConn struct {
	// contains filtered or unexported fields
}

TestSubConn implements the SubConn interface, to be used in tests.

func (*TestSubConn) Connect

func (tsc *TestSubConn) Connect()

Connect is a no-op.

func (*TestSubConn) String

func (tsc *TestSubConn) String() string

String implements stringer to print human friendly error message.

func (*TestSubConn) UpdateAddresses

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 an xDS server.
Package fakeserver provides a fake implementation of an xDS server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL