package testonly
import "github.com/google/trillian/util/election2/testonly"
Package testonly contains an Election implementation for testing.
Index ¶
- Variables
- type Decorator
- func NewDecorator(e election2.Election) *Decorator
- func (d *Decorator) Await(ctx context.Context) error
- func (d *Decorator) BlockAwait(block bool)
- func (d *Decorator) Close(ctx context.Context) error
- func (d *Decorator) Resign(ctx context.Context) error
- func (d *Decorator) Update(errs Errs)
- func (d *Decorator) WithMastership(ctx context.Context) (context.Context, error)
- type Election
- func NewElection() *Election
- func (e *Election) Await(ctx context.Context) error
- func (e *Election) Close(ctx context.Context) error
- func (e *Election) Resign(ctx context.Context) error
- func (e *Election) WithMastership(ctx context.Context) (context.Context, error)
- type Errs
- type NamedTest
Variables ¶
var Factory factory
Factory allows creating Election instances for testing.
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.
Types ¶
type Decorator ¶
type Decorator struct {
// contains filtered or unexported fields
}
Decorator is an election2.Election decorator injecting errors, for testing.
func NewDecorator ¶
NewDecorator returns a Decorator wrapping the passed in Election object.
func (*Decorator) Await ¶
Await blocks until the instance captures mastership.
func (*Decorator) BlockAwait ¶
BlockAwait enables or disables Await method blocking.
func (*Decorator) Close ¶
Close permanently stops participating in election.
func (*Decorator) Resign ¶
Resign releases mastership for this instance.
func (*Decorator) Update ¶
Update updates errors returned by interface methods.
func (*Decorator) WithMastership ¶
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 ¶
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 ¶
Close resets mastership permanently.
func (*Election) Resign ¶
Resign resets mastership.
func (*Election) WithMastership ¶
WithMastership returns mastership context, which gets canceled if / when this instance is not / stops being the master.
type Errs ¶
Errs contains errors to be returned by each of Election methods.
type NamedTest ¶
NamedTest is a test function paired with its string name.
Source Files ¶
decorator.go election.go tests.go
- Version
- v1.7.1 (latest)
- Published
- Jan 9, 2025
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 5 days ago –
Tools for package owners.