...

Package rafttest

import "go.etcd.io/etcd/raft/v3/rafttest"
Overview
Index

Overview ▾

Package rafttest provides functional tests for etcd's raft implementation.

Index ▾

type InteractionEnv
    func NewInteractionEnv(opts *InteractionOpts) *InteractionEnv
    func (env *InteractionEnv) AddNodes(n int, snap pb.Snapshot) error
    func (env *InteractionEnv) Campaign(t *testing.T, idx int) error
    func (env *InteractionEnv) Compact(idx int, newFirstIndex uint64) error
    func (env *InteractionEnv) DeliverMsgs(rs ...Recipient) int
    func (env *InteractionEnv) Handle(t *testing.T, d datadriven.TestData) string
    func (env *InteractionEnv) LogLevel(name string) error
    func (env *InteractionEnv) ProcessReady(idx int) error
    func (env *InteractionEnv) Propose(idx int, data []byte) error
    func (env *InteractionEnv) ProposeConfChange(idx int, c raftpb.ConfChangeI) error
    func (env *InteractionEnv) RaftLog(idx int) error
    func (env *InteractionEnv) Stabilize(idxs ...int) error
    func (env *InteractionEnv) Status(idx int) error
    func (env *InteractionEnv) Tick(idx int, num int) error
type InteractionOpts
type Node
type Recipient
type RedirectLogger
    func (l *RedirectLogger) Debug(v ...interface{})
    func (l *RedirectLogger) Debugf(format string, v ...interface{})
    func (l *RedirectLogger) Error(v ...interface{})
    func (l *RedirectLogger) Errorf(format string, v ...interface{})
    func (l *RedirectLogger) Fatal(v ...interface{})
    func (l *RedirectLogger) Fatalf(format string, v ...interface{})
    func (l *RedirectLogger) Info(v ...interface{})
    func (l *RedirectLogger) Infof(format string, v ...interface{})
    func (l *RedirectLogger) Panic(v ...interface{})
    func (l *RedirectLogger) Panicf(format string, v ...interface{})
    func (l *RedirectLogger) Warning(v ...interface{})
    func (l *RedirectLogger) Warningf(format string, v ...interface{})
type Storage

Package files

doc.go interaction_env.go interaction_env_handler.go interaction_env_handler_add_nodes.go interaction_env_handler_campaign.go interaction_env_handler_compact.go interaction_env_handler_deliver_msgs.go interaction_env_handler_log_level.go interaction_env_handler_process_ready.go interaction_env_handler_propose.go interaction_env_handler_propose_conf_change.go interaction_env_handler_raft_log.go interaction_env_handler_stabilize.go interaction_env_handler_status.go interaction_env_handler_tick_heartbeat.go interaction_env_logger.go network.go node.go

type InteractionEnv

InteractionEnv facilitates testing of complex interactions between the members of a raft group.

type InteractionEnv struct {
    Options  *InteractionOpts
    Nodes    []Node
    Messages []pb.Message // in-flight messages

    Output *RedirectLogger
}

func NewInteractionEnv

func NewInteractionEnv(opts *InteractionOpts) *InteractionEnv

NewInteractionEnv initializes an InteractionEnv. opts may be nil.

func (*InteractionEnv) AddNodes

func (env *InteractionEnv) AddNodes(n int, snap pb.Snapshot) error

AddNodes adds n new nodes initializes from the given snapshot (which may be empty). They will be assigned consecutive IDs.

func (*InteractionEnv) Campaign

func (env *InteractionEnv) Campaign(t *testing.T, idx int) error

Campaign the node at the given index.

func (*InteractionEnv) Compact

func (env *InteractionEnv) Compact(idx int, newFirstIndex uint64) error

Compact truncates the log on the node at index idx so that the supplied new first index results.

func (*InteractionEnv) DeliverMsgs

func (env *InteractionEnv) DeliverMsgs(rs ...Recipient) int

DeliverMsgs goes through env.Messages and, depending on the Drop flag, delivers or drops messages to the specified Recipients. Returns the number of messages handled (i.e. delivered or dropped). A handled message is removed from env.Messages.

func (*InteractionEnv) Handle

func (env *InteractionEnv) Handle(t *testing.T, d datadriven.TestData) string

Handle is the entrypoint for data-driven interaction testing. Commands and parameters are parsed from the supplied TestData. Errors during data parsing are reported via the supplied *testing.T; errors from the raft nodes and the storage engine are reported to the output buffer.

func (*InteractionEnv) LogLevel

func (env *InteractionEnv) LogLevel(name string) error

func (*InteractionEnv) ProcessReady

func (env *InteractionEnv) ProcessReady(idx int) error

ProcessReady runs Ready handling on the node with the given index.

func (*InteractionEnv) Propose

func (env *InteractionEnv) Propose(idx int, data []byte) error

Propose a regular entry.

func (*InteractionEnv) ProposeConfChange

func (env *InteractionEnv) ProposeConfChange(idx int, c raftpb.ConfChangeI) error

ProposeConfChange proposes a configuration change on the node with the given index.

func (*InteractionEnv) RaftLog

func (env *InteractionEnv) RaftLog(idx int) error

RaftLog pretty prints the raft log to the output buffer.

func (*InteractionEnv) Stabilize

func (env *InteractionEnv) Stabilize(idxs ...int) error

Stabilize repeatedly runs Ready handling on and message delivery to the set of nodes specified via the idxs slice until reaching a fixed point.

func (*InteractionEnv) Status

func (env *InteractionEnv) Status(idx int) error

Status pretty-prints the raft status for the node at the given index to the output buffer.

func (*InteractionEnv) Tick

func (env *InteractionEnv) Tick(idx int, num int) error

Tick the node at the given index the given number of times.

type InteractionOpts

InteractionOpts groups the options for an InteractionEnv.

type InteractionOpts struct {
    OnConfig func(*raft.Config)
}

type Node

Node is a member of a raft group tested via an InteractionEnv.

type Node struct {
    *raft.RawNode
    Storage

    Config  *raft.Config
    History []pb.Snapshot
}

type Recipient

type Recipient struct {
    ID   uint64
    Drop bool
}

type RedirectLogger

type RedirectLogger struct {
    *strings.Builder
    Lvl int // 0 = DEBUG, 1 = INFO, 2 = WARNING, 3 = ERROR, 4 = FATAL, 5 = NONE
}

func (*RedirectLogger) Debug

func (l *RedirectLogger) Debug(v ...interface{})

func (*RedirectLogger) Debugf

func (l *RedirectLogger) Debugf(format string, v ...interface{})

func (*RedirectLogger) Error

func (l *RedirectLogger) Error(v ...interface{})

func (*RedirectLogger) Errorf

func (l *RedirectLogger) Errorf(format string, v ...interface{})

func (*RedirectLogger) Fatal

func (l *RedirectLogger) Fatal(v ...interface{})

func (*RedirectLogger) Fatalf

func (l *RedirectLogger) Fatalf(format string, v ...interface{})

func (*RedirectLogger) Info

func (l *RedirectLogger) Info(v ...interface{})

func (*RedirectLogger) Infof

func (l *RedirectLogger) Infof(format string, v ...interface{})

func (*RedirectLogger) Panic

func (l *RedirectLogger) Panic(v ...interface{})

func (*RedirectLogger) Panicf

func (l *RedirectLogger) Panicf(format string, v ...interface{})

func (*RedirectLogger) Warning

func (l *RedirectLogger) Warning(v ...interface{})

func (*RedirectLogger) Warningf

func (l *RedirectLogger) Warningf(format string, v ...interface{})

type Storage

Storage is the interface used by InteractionEnv. It is comprised of raft's Storage interface plus access to operations that maintain the log and drive the Ready handling loop.

type Storage interface {
    raft.Storage
    SetHardState(state pb.HardState) error
    ApplySnapshot(pb.Snapshot) error
    Compact(newFirstIndex uint64) error
    Append([]pb.Entry) error
}