integration

package
v0.0.0-...-b45d6de Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: Apache-2.0 Imports: 56 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RequestWaitTimeout is the time duration to wait for a request to go through or detect leader loss.
	RequestWaitTimeout = 5 * time.Second
	RequestTimeout     = 20 * time.Second

	ClusterName  = "etcd"
	BasePort     = 21000
	URLScheme    = "http"
	URLSchemeTLS = "https"
	BaseGRPCPort = 30000
)
View Source
const ThroughProxy = false

Variables

View Source
var (
	ElectionTicks = 10

	// UniqueCount integration test is used to set unique member ids
	UniqueCount = int32(0)

	TestTLSInfo = transport.TLSInfo{
		KeyFile:        testutils.MustAbsPath("../fixtures/server.key.insecure"),
		CertFile:       testutils.MustAbsPath("../fixtures/server.crt"),
		TrustedCAFile:  testutils.MustAbsPath("../fixtures/ca.crt"),
		ClientCertAuth: true,
	}

	TestTLSInfoWithSpecificUsage = transport.TLSInfo{
		KeyFile:        testutils.MustAbsPath("../fixtures/server-serverusage.key.insecure"),
		CertFile:       testutils.MustAbsPath("../fixtures/server-serverusage.crt"),
		ClientKeyFile:  testutils.MustAbsPath("../fixtures/client-clientusage.key.insecure"),
		ClientCertFile: testutils.MustAbsPath("../fixtures/client-clientusage.crt"),
		TrustedCAFile:  testutils.MustAbsPath("../fixtures/ca.crt"),
		ClientCertAuth: true,
	}

	TestTLSInfoIP = transport.TLSInfo{
		KeyFile:        testutils.MustAbsPath("../fixtures/server-ip.key.insecure"),
		CertFile:       testutils.MustAbsPath("../fixtures/server-ip.crt"),
		TrustedCAFile:  testutils.MustAbsPath("../fixtures/ca.crt"),
		ClientCertAuth: true,
	}

	TestTLSInfoExpired = transport.TLSInfo{
		KeyFile:        testutils.MustAbsPath("./fixtures-expired/server.key.insecure"),
		CertFile:       testutils.MustAbsPath("./fixtures-expired/server.crt"),
		TrustedCAFile:  testutils.MustAbsPath("./fixtures-expired/ca.crt"),
		ClientCertAuth: true,
	}

	TestTLSInfoExpiredIP = transport.TLSInfo{
		KeyFile:        testutils.MustAbsPath("./fixtures-expired/server-ip.key.insecure"),
		CertFile:       testutils.MustAbsPath("./fixtures-expired/server-ip.crt"),
		TrustedCAFile:  testutils.MustAbsPath("./fixtures-expired/ca.crt"),
		ClientCertAuth: true,
	}

	DefaultTokenJWT = fmt.Sprintf("jwt,pub-key=%s,priv-key=%s,sign-method=RS256,ttl=1s",
		testutils.MustAbsPath("../fixtures/server.crt"), testutils.MustAbsPath("../fixtures/server.key.insecure"))

	// UniqueNumber is used to generate unique port numbers
	// Should only be accessed via atomic package methods.
	UniqueNumber int32
)

Functions

func BeforeTest

func BeforeTest(t testutil.TB, opts ...TestOption)

func BeforeTestExternal

func BeforeTestExternal(t testutil.TB)

BeforeTestExternal initializes test context and is targeted for external APIs. In general the `integration` package is not targeted to be used outside of etcd project, but till the dedicated package is developed, this is the best entry point so far (without backward compatibility promise).

func CheckLeaderTransition

func CheckLeaderTransition(m *Member, oldLead uint64) uint64

CheckLeaderTransition waits for leader transition, returning the new leader ID.

func CloseClients

func CloseClients(t testutil.TB, clients []*clientv3.Client)

CloseClients closes all the clients from the 'clients' list.

func MakeMultiNodeClients

func MakeMultiNodeClients(t testutil.TB, clus *Cluster, clients *[]*clientv3.Client) func() *clientv3.Client

MakeMultiNodeClients creates factory of clients that all connect to random members. All the created clients are put on the 'clients' list. The factory is thread-safe.

func MakeSingleNodeClients

func MakeSingleNodeClients(t testutil.TB, clus *Cluster, clients *[]*clientv3.Client) func() *clientv3.Client

MakeSingleNodeClients creates factory of clients that all connect to member 0. All the created clients are put on the 'clients' list. The factory is thread-safe.

func NewClient

func NewClient(t testing.TB, cfg clientv3.Config) (*clientv3.Client, error)

func NewClientV3

func NewClientV3(m *Member) (*clientv3.Client, error)

NewClientV3 creates a new grpc client connection to the member

func NewEmbedConfig

func NewEmbedConfig(t testing.TB, name string) *embed.Config

func NewIntegrationRunner

func NewIntegrationRunner() intf.TestRunner

func NewListenerWithAddr

func NewListenerWithAddr(t testutil.TB, addr string) net.Listener

func NewLocalListener

func NewLocalListener(t testutil.TB) net.Listener

func SchemeFromTLSInfo

func SchemeFromTLSInfo(tls *transport.TLSInfo) string

func WaitClientV3

func WaitClientV3(t testutil.TB, kv clientv3.KV)

func WaitClientV3WithKey

func WaitClientV3WithKey(t testutil.TB, kv clientv3.KV, key string)

func WithAuth

func WithAuth(userName, password string) framecfg.ClientOption

func WithEndpoints

func WithEndpoints(endpoints []string) framecfg.ClientOption

Types

type Cluster

type Cluster struct {
	Cfg           *ClusterConfig
	Members       []*Member
	LastMemberNum int
	// contains filtered or unexported fields
}

func NewCluster

func NewCluster(t testutil.TB, cfg *ClusterConfig) *Cluster

NewCluster returns a launched Cluster with a grpc client connection for each Cluster member.

func (*Cluster) AddAndLaunchLearnerMember

func (c *Cluster) AddAndLaunchLearnerMember(t testutil.TB)

AddAndLaunchLearnerMember creates a learner member, adds it to Cluster via v3 MemberAdd API, and then launches the new member.

func (*Cluster) AddMember

func (c *Cluster) AddMember(t testutil.TB) types.URLs

AddMember return PeerURLs of the added member.

func (*Cluster) AddMemberByURL

func (c *Cluster) AddMemberByURL(t testutil.TB, cc *clientv3.Client, peerURL string) error

func (*Cluster) Client

func (c *Cluster) Client(i int) *clientv3.Client

func (*Cluster) ClusterClient

func (c *Cluster) ClusterClient(t testing.TB, opts ...framecfg.ClientOption) (client *clientv3.Client, err error)

func (*Cluster) Endpoints

func (c *Cluster) Endpoints() []string

func (*Cluster) GetLearnerMembers

func (c *Cluster) GetLearnerMembers() ([]*pb.Member, error)

GetLearnerMembers returns the list of learner members in Cluster using MemberList API.

func (*Cluster) Launch

func (c *Cluster) Launch(t testutil.TB)

func (*Cluster) MustNewMember

func (c *Cluster) MustNewMember(t testutil.TB, resp *clientv3.MemberAddResponse) *Member

MustNewMember creates a new member instance based on the response of V3 Member Add API.

func (*Cluster) NewClientV3

func (c *Cluster) NewClientV3(memberIndex int) (*clientv3.Client, error)

NewClientV3 creates a new grpc client connection to the member

func (*Cluster) ProtoMembers

func (c *Cluster) ProtoMembers() []*pb.Member

ProtoMembers returns a list of all active members as client.Members

func (*Cluster) RandClient

func (c *Cluster) RandClient() *clientv3.Client

func (*Cluster) RemoveMember

func (c *Cluster) RemoveMember(t testutil.TB, cc *clientv3.Client, id uint64) error

func (*Cluster) TakeClient

func (c *Cluster) TakeClient(idx int)

func (*Cluster) Terminate

func (c *Cluster) Terminate(t testutil.TB)

func (*Cluster) WaitLeader

func (c *Cluster) WaitLeader(t testing.TB) int

WaitLeader returns index of the member in c.Members that is leader or fails the test (if not established in 30s).

func (*Cluster) WaitMembersForLeader

func (c *Cluster) WaitMembersForLeader(t testing.TB, membs []*Member) int

WaitMembersForLeader waits until given members agree on the same leader, and returns its 'index' in the 'membs' list

func (*Cluster) WaitMembersMatch

func (c *Cluster) WaitMembersMatch(t testutil.TB, membs []*pb.Member)

func (*Cluster) WaitMembersNoLeader

func (c *Cluster) WaitMembersNoLeader(membs []*Member)

WaitMembersNoLeader waits until given members lose leader.

func (*Cluster) WaitNoLeader

func (c *Cluster) WaitNoLeader()

type ClusterConfig

type ClusterConfig struct {
	Size      int
	PeerTLS   *transport.TLSInfo
	ClientTLS *transport.TLSInfo

	DiscoveryURL string

	AuthToken    string
	AuthTokenTTL uint

	QuotaBackendBytes int64

	MaxTxnOps              uint
	MaxRequestBytes        uint
	SnapshotCount          uint64
	SnapshotCatchUpEntries uint64

	GRPCKeepAliveMinTime  time.Duration
	GRPCKeepAliveInterval time.Duration
	GRPCKeepAliveTimeout  time.Duration

	ClientMaxCallSendMsgSize int
	ClientMaxCallRecvMsgSize int

	// UseIP is true to use only IP for gRPC requests.
	UseIP bool
	// UseBridge adds bridge between client and grpc server. Should be used in tests that
	// want to manipulate connection or require connection not breaking despite server stop/restart.
	UseBridge bool
	// UseTCP configures server listen on tcp socket. If disabled unix socket is used.
	UseTCP bool

	EnableLeaseCheckpoint   bool
	LeaseCheckpointInterval time.Duration
	LeaseCheckpointPersist  bool

	WatchProgressNotifyInterval time.Duration
	ExperimentalMaxLearners     int
	DisableStrictReconfigCheck  bool
	CorruptCheckTime            time.Duration
}

type Dialer

type Dialer interface {
	Dial() (net.Conn, error)
}

type GrpcAPI

type GrpcAPI struct {
	// Cluster is the Cluster API for the client'Server connection.
	Cluster pb.ClusterClient
	// KV is the keyvalue API for the client'Server connection.
	KV pb.KVClient
	// Lease is the lease API for the client'Server connection.
	Lease pb.LeaseClient
	// Watch is the watch API for the client'Server connection.
	Watch pb.WatchClient
	// Maintenance is the maintenance API for the client'Server connection.
	Maintenance pb.MaintenanceClient
	// Auth is the authentication API for the client'Server connection.
	Auth pb.AuthClient
	// Lock is the lock API for the client'Server connection.
	Lock lockpb.LockClient
	// Election is the election API for the client'Server connection.
	Election epb.ElectionClient
}

func ToGRPC

func ToGRPC(c *clientv3.Client) GrpcAPI

type Member

type Member struct {
	config.ServerConfig
	UniqNumber                     int
	MemberNumber                   int
	Port                           string
	PeerListeners, ClientListeners []net.Listener
	GrpcListener                   net.Listener
	// PeerTLSInfo enables peer TLS when set
	PeerTLSInfo *transport.TLSInfo
	// ClientTLSInfo enables client TLS when set
	ClientTLSInfo *transport.TLSInfo
	DialOptions   []grpc.DialOption

	RaftHandler   *testutil.PauseableHandler
	Server        *etcdserver.EtcdServer
	ServerClosers []func()

	GrpcServerOpts []grpc.ServerOption
	GrpcServer     *grpc.Server
	GrpcURL        string
	GrpcBridge     *bridge

	// ServerClient is a clientv3 that directly calls the etcdserver.
	ServerClient *clientv3.Client
	// Client is a clientv3 that communicates via socket, either UNIX or TCP.
	Client *clientv3.Client

	KeepDataDirTerminate     bool
	ClientMaxCallSendMsgSize int
	ClientMaxCallRecvMsgSize int
	UseIP                    bool
	UseBridge                bool
	UseTCP                   bool

	IsLearner bool
	Closed    bool

	GrpcServerRecorder *grpc_testing.GrpcRecorder

	LogObserver *testutils.LogObserver
}

func MustNewMember

func MustNewMember(t testutil.TB, mcfg MemberConfig) *Member

MustNewMember return an inited member with the given name. If peerTLS is set, it will use https scheme to communicate between peers.

func (*Member) Bridge

func (m *Member) Bridge() *bridge

func (*Member) Clone

func (m *Member) Clone(t testutil.TB) *Member

Clone returns a member with the same server configuration. The returned member will not set PeerListeners and ClientListeners.

func (*Member) Close

func (m *Member) Close()

Close stops the member'Server etcdserver and closes its connections

func (*Member) ElectionTimeout

func (m *Member) ElectionTimeout() time.Duration

func (*Member) GRPCURL

func (m *Member) GRPCURL() string

func (*Member) GrpcPortNumber

func (m *Member) GrpcPortNumber() string

func (*Member) ID

func (m *Member) ID() types.ID

func (*Member) InjectPartition

func (m *Member) InjectPartition(t testutil.TB, others ...*Member)

InjectPartition drops connections from m to others, vice versa.

func (*Member) Launch

func (m *Member) Launch() error

Launch starts a member based on ServerConfig, PeerListeners and ClientListeners.

func (*Member) Metric

func (m *Member) Metric(metricName string, expectLabels ...string) (string, error)

Metric gets the metric value for a member

func (*Member) Pause

func (m *Member) Pause()

func (*Member) ReadyNotify

func (m *Member) ReadyNotify() <-chan struct{}

func (*Member) RecordedRequests

func (m *Member) RecordedRequests() []grpc_testing.RequestInfo

func (*Member) RecoverPartition

func (m *Member) RecoverPartition(t testutil.TB, others ...*Member)

RecoverPartition recovers connections from m to others, vice versa.

func (*Member) Restart

func (m *Member) Restart(t testutil.TB) error

Restart starts the member using the preserved data dir.

func (*Member) Resume

func (m *Member) Resume()

func (*Member) Stop

func (m *Member) Stop(_ testutil.TB)

Stop stops the member, but the data dir of the member is preserved.

func (*Member) StopNotify

func (m *Member) StopNotify() <-chan struct{}

StopNotify unblocks when a member stop completes

func (*Member) Terminate

func (m *Member) Terminate(t testutil.TB)

Terminate stops the member and removes the data dir.

func (*Member) URL

func (m *Member) URL() string

func (*Member) WaitOK

func (m *Member) WaitOK(t testutil.TB)

func (*Member) WaitStarted

func (m *Member) WaitStarted(t testutil.TB)

type MemberConfig

type MemberConfig struct {
	Name                        string
	UniqNumber                  int64
	MemberNumber                int
	PeerTLS                     *transport.TLSInfo
	ClientTLS                   *transport.TLSInfo
	AuthToken                   string
	AuthTokenTTL                uint
	QuotaBackendBytes           int64
	MaxTxnOps                   uint
	MaxRequestBytes             uint
	SnapshotCount               uint64
	SnapshotCatchUpEntries      uint64
	GrpcKeepAliveMinTime        time.Duration
	GrpcKeepAliveInterval       time.Duration
	GrpcKeepAliveTimeout        time.Duration
	ClientMaxCallSendMsgSize    int
	ClientMaxCallRecvMsgSize    int
	UseIP                       bool
	UseBridge                   bool
	UseTCP                      bool
	EnableLeaseCheckpoint       bool
	LeaseCheckpointInterval     time.Duration
	LeaseCheckpointPersist      bool
	WatchProgressNotifyInterval time.Duration
	ExperimentalMaxLearners     int
	DisableStrictReconfigCheck  bool
	CorruptCheckTime            time.Duration
}

type SortableMemberSliceByPeerURLs

type SortableMemberSliceByPeerURLs []*pb.Member

func (SortableMemberSliceByPeerURLs) Len

func (SortableMemberSliceByPeerURLs) Less

func (p SortableMemberSliceByPeerURLs) Less(i, j int) bool

func (SortableMemberSliceByPeerURLs) Swap

func (p SortableMemberSliceByPeerURLs) Swap(i, j int)

type SortableProtoMemberSliceByPeerURLs

type SortableProtoMemberSliceByPeerURLs []*pb.Member

func (SortableProtoMemberSliceByPeerURLs) Len

func (SortableProtoMemberSliceByPeerURLs) Less

func (SortableProtoMemberSliceByPeerURLs) Swap

type TestOption

type TestOption func(opt *testOptions)

func WithoutGoLeakDetection

func WithoutGoLeakDetection() TestOption

WithoutGoLeakDetection disables checking whether a testcase leaked a goroutine.

func WithoutSkipInShort

func WithoutSkipInShort() TestOption

Jump to

Keyboard shortcuts

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