etcd: go.etcd.io/etcd/pkg/testutil Index | Files

package testutil

import "go.etcd.io/etcd/pkg/testutil"

Package testutil provides test utility functions.

Index

Package Files

assert.go leak.go pauseable_handler.go recorder.go testutil.go var.go

Variables

var (
    ApplyTimeout   = time.Second
    RequestTimeout = 3 * time.Second
)

func AfterTest Uses

func AfterTest(t *testing.T)

AfterTest is meant to run in a defer that executes after a test completes. It will detect common goroutine leaks, retrying in case there are goroutines not synchronously torn down, and fail the test if any goroutines are stuck.

func AssertEqual Uses

func AssertEqual(t *testing.T, e, a interface{}, msg ...string)

func AssertFalse Uses

func AssertFalse(t *testing.T, v bool, msg ...string)

func AssertNil Uses

func AssertNil(t *testing.T, v interface{})

func AssertNotNil Uses

func AssertNotNil(t *testing.T, v interface{})

func AssertTrue Uses

func AssertTrue(t *testing.T, v bool, msg ...string)

func CheckAfterTest Uses

func CheckAfterTest(d time.Duration) error

CheckAfterTest returns an error if AfterTest would fail with an error.

func CheckLeakedGoroutine Uses

func CheckLeakedGoroutine() bool

CheckLeakedGoroutine verifies tests do not leave any leaky goroutines. It returns true when there are goroutines still running(leaking) after all tests.

import "go.etcd.io/etcd/pkg/testutil"

func TestMain(m *testing.M) {
	v := m.Run()
	if v == 0 && testutil.CheckLeakedGoroutine() {
		os.Exit(1)
	}
	os.Exit(v)
}

func TestSample(t *testing.T) {
	defer testutil.AfterTest(t)
	...
}

func FatalStack Uses

func FatalStack(t *testing.T, s string)

FatalStack helps to fatal the test and print out the stacks of all running goroutines.

func MustNewURL Uses

func MustNewURL(t *testing.T, s string) *url.URL

func MustNewURLs Uses

func MustNewURLs(t *testing.T, urls []string) []url.URL

func Poll Uses

func Poll(interval time.Duration, timeout time.Duration, condition ConditionFunc) (bool, error)

Poll calls a condition function repeatedly on a polling interval until it returns true, returns an error or the timeout is reached. If the condition function returns true or an error before the timeout, Poll immediately returns with the true value or the error. If the timeout is exceeded, Poll returns false.

func WaitSchedule Uses

func WaitSchedule()

WaitSchedule briefly sleeps in order to invoke the go scheduler. TODO: improve this when we are able to know the schedule or status of target go-routine.

type Action Uses

type Action struct {
    Name   string
    Params []interface{}
}

type ConditionFunc Uses

type ConditionFunc func() (bool, error)

ConditionFunc returns true when a condition is met.

type PauseableHandler Uses

type PauseableHandler struct {
    Next http.Handler
    // contains filtered or unexported fields
}

func (*PauseableHandler) Pause Uses

func (ph *PauseableHandler) Pause()

func (*PauseableHandler) Resume Uses

func (ph *PauseableHandler) Resume()

func (*PauseableHandler) ServeHTTP Uses

func (ph *PauseableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Recorder Uses

type Recorder interface {
    // Record publishes an Action (e.g., function call) which will
    // be reflected by Wait() or Chan()
    Record(a Action)
    // Wait waits until at least n Actions are available or returns with error
    Wait(n int) ([]Action, error)
    // Action returns immediately available Actions
    Action() []Action
    // Chan returns the channel for actions published by Record
    Chan() <-chan Action
}

func NewRecorderStream Uses

func NewRecorderStream() Recorder

type RecorderBuffered Uses

type RecorderBuffered struct {
    sync.Mutex
    // contains filtered or unexported fields
}

RecorderBuffered appends all Actions to a slice

func (*RecorderBuffered) Action Uses

func (r *RecorderBuffered) Action() []Action

func (*RecorderBuffered) Chan Uses

func (r *RecorderBuffered) Chan() <-chan Action

func (*RecorderBuffered) Record Uses

func (r *RecorderBuffered) Record(a Action)

func (*RecorderBuffered) Wait Uses

func (r *RecorderBuffered) Wait(n int) (acts []Action, err error)

Package testutil imports 13 packages (graph) and is imported by 24 packages. Updated 2019-01-28. Refresh now. Tools for package owners.