juju: github.com/exekias/juju/worker/workertest Index | Files

package workertest

import "github.com/exekias/juju/worker/workertest"

Index

Package Files

check.go workers.go

func CheckAlive Uses

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 Uses

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 Uses

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 CleanKill Uses

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 Uses

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 Uses

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 Uses

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.

type ForeverWorker Uses

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

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

func NewForeverWorker Uses

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 Uses

func (w *ForeverWorker) Kill()

Kill is part of the worker.Worker interface.

func (*ForeverWorker) ReallyKill Uses

func (w *ForeverWorker) ReallyKill()

ReallyKill does what Kill should.

func (*ForeverWorker) Wait Uses

func (w *ForeverWorker) Wait() error

Wait is part of the worker.Worker interface.

Package workertest imports 7 packages (graph). Updated 2016-07-29. Refresh now. Tools for package owners. This is a dead-end fork (no commits since the fork).