workertest

package
v3.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: LGPL-3.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAlive

func CheckAlive(c *gc.C, w worker.Worker)

CheckAlive Wait()s a short time for the supplied worker to return an error, and fails the test if it does. If it doesn't fail, it'll leave a goroutine running in the background, blocked on the worker's death; but that doesn't matter, because of *course* you correctly deferred a suitable Kill helper as soon as you created the worker in the first place. Right? Right.

It doesn't Assert and is therefore suitable for use from any goroutine.

func CheckKill

func CheckKill(c *gc.C, w worker.Worker) error

CheckKill Kill()s the supplied worker and Wait()s for its error, which it returns for further analysis, or fails the test after a timeout expires. It doesn't Assert and is therefore suitable for use from any goroutine.

func CheckKilled

func CheckKilled(c *gc.C, w worker.Worker) error

CheckKilled Wait()s for the supplied worker's error, which it returns for further analysis, or fails the test after a timeout expires. It doesn't Assert and is therefore suitable for use from any goroutine.

func CheckNilOrKill

func CheckNilOrKill(c *gc.C, w worker.Worker)

CheckNilOrKill has no effect if w is nil; otherwise, it fails the test and tries to stop the (non-nil) worker via CleanKill(). It's suitable for testing constructor failure:

someWorker, err := some.NewWorker(badConfig)
workertest.CheckNilOrKill(c, someWorker)
c.Check(err, ...

...because it will do the right thing if your constructor succeeds unexpectedly, and make every effort to prevent a rogue worker living beyond its test.

func CleanKill

func CleanKill(c *gc.C, w worker.Worker)

CleanKill calls CheckKill with the supplied arguments, and Checks that the returned error is nil. It's particularly suitable for deferring:

someWorker, err := some.NewWorker()
c.Assert(err, jc.ErrorIsNil)
defer workertest.CleanKill(c, someWorker)

...in the large number (majority?) of situations where a worker is expected to run successfully; and it doesn't Assert, and is therefore suitable for use from any goroutine.

func DirtyKill

func DirtyKill(c *gc.C, w worker.Worker)

DirtyKill calls CheckKill with the supplied arguments, and logs the returned error. It's particularly suitable for deferring:

someWorker, err := some.NewWorker()
c.Assert(err, jc.ErrorIsNil)
defer workertest.DirtyKill(c, someWorker)

...in the cases where we expect a worker to fail, but aren't specifically testing that failure; and it doesn't Assert, and is therefore suitable for use from any goroutine.

func NewDeadWorker

func NewDeadWorker(err error) worker.Worker

NewDeadWorker returns a Worker that's already dead, and always immediately returns the supplied error from Wait().

func NewErrorWorker

func NewErrorWorker(err error) worker.Worker

NewErrorWorker returns a Worker that runs until Kill()ed; at which point it fails with the supplied error. The caller takes responsibility for causing it to be Kill()ed, lest the goroutine be leaked, but the worker has no outside interactions or safety concerns so there's no particular need to Wait() for it.

Types

type ForeverWorker

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

ForeverWorker is a Worker that breaks its contract. Use with care.

func NewForeverWorker

func NewForeverWorker(err error) *ForeverWorker

NewForeverWorker returns a Worker that ignores Kill() calls. You must be sure to call ReallyKill() to cause the worker to fail with the supplied error, lest any goroutines trying to manage it be leaked or blocked forever.

func (*ForeverWorker) Kill

func (w *ForeverWorker) Kill()

Kill is part of the worker.Worker interface.

func (*ForeverWorker) ReallyKill

func (w *ForeverWorker) ReallyKill()

ReallyKill does what Kill should.

func (*ForeverWorker) Wait

func (w *ForeverWorker) Wait() error

Wait is part of the worker.Worker interface.

type NotAWatcher

type NotAWatcher struct {
	worker.Worker
	// contains filtered or unexported fields
}

func NewFakeWatcher

func NewFakeWatcher(len, preload int) NotAWatcher

NewFakeWatcher returns a fake watcher

func (NotAWatcher) Changes

func (w NotAWatcher) Changes() <-chan struct{}

func (*NotAWatcher) Close

func (w *NotAWatcher) Close()

func (NotAWatcher) Err

func (w NotAWatcher) Err() error

func (*NotAWatcher) Ping

func (w *NotAWatcher) Ping()

func (NotAWatcher) Stop

func (w NotAWatcher) Stop() error

Jump to

Keyboard shortcuts

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