testonly

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package testonly contains an Election implementation for testing.

Index

Constants

This section is empty.

Variables

View Source
var Factory factory

Factory allows creating Election instances for testing.

View Source
var Tests = []NamedTest{
	{Name: "RunElectionAwait", Run: runElectionAwait},
	{Name: "RunElectionWithMastership", Run: runElectionWithMastership},
	{Name: "RunElectionResign", Run: runElectionResign},
	{Name: "RunElectionClose", Run: runElectionClose},
	{Name: "RunElectionLoop", Run: runElectionLoop},
}

Tests is the full list of available Election tests. TODO(pavelkalinnikov): Add tests for unexpected mastership loss.

Functions

This section is empty.

Types

type Decorator

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

Decorator is an election2.Election decorator injecting errors, for testing.

func NewDecorator

func NewDecorator(e election2.Election) *Decorator

NewDecorator returns a Decorator wrapping the passed in Election object.

func (*Decorator) Await

func (d *Decorator) Await(ctx context.Context) error

Await blocks until the instance captures mastership.

func (*Decorator) BlockAwait

func (d *Decorator) BlockAwait(block bool)

BlockAwait enables or disables Await method blocking.

func (*Decorator) Close

func (d *Decorator) Close(ctx context.Context) error

Close permanently stops participating in election.

func (*Decorator) Resign

func (d *Decorator) Resign(ctx context.Context) error

Resign releases mastership for this instance.

func (*Decorator) Update

func (d *Decorator) Update(errs Errs)

Update updates errors returned by interface methods.

func (*Decorator) WithMastership

func (d *Decorator) WithMastership(ctx context.Context) (context.Context, error)

WithMastership returns a mastership context.

type Election

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

Election implements election2.Election interface for testing.

func NewElection

func NewElection() *Election

NewElection returns a new initialized Election for testing.

func (*Election) Await

func (e *Election) Await(ctx context.Context) error

Await sets this instance to be the master. It always succeeds. To imitate errors and/or blocking behavior use the Decorator type.

func (*Election) Close

func (e *Election) Close(ctx context.Context) error

Close resets mastership permanently.

func (*Election) Resign

func (e *Election) Resign(ctx context.Context) error

Resign resets mastership.

func (*Election) WithMastership

func (e *Election) WithMastership(ctx context.Context) (context.Context, error)

WithMastership returns mastership context, which gets canceled if / when this instance is not / stops being the master.

type Errs

type Errs struct {
	Await          error
	WithMastership error
	Resign         error
	Close          error
}

Errs contains errors to be returned by each of Election methods.

type NamedTest

type NamedTest struct {
	Name string
	Run  func(t *testing.T, f election2.Factory)
}

NamedTest is a test function paired with its string name.

Jump to

Keyboard shortcuts

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