Exemplo n.º 1
0
func (*WorkerSuite) TestStopKills(c *gc.C) {
	w := workertest.NewErrorWorker(nil)
	defer workertest.CleanKill(c, w)

	worker.Stop(w)
	workertest.CheckKilled(c, w)
}
Exemplo n.º 2
0
func (*OccupySuite) TestStartSuccess(c *gc.C) {
	fix := newFixture(c)
	defer fix.TearDown(c)
	c.Check(fix.Guard(c).Unlock(), jc.ErrorIsNil)

	// Start a worker...
	expect := workertest.NewErrorWorker(nil)
	defer workertest.CleanKill(c, expect)
	run := func() (worker.Worker, error) {
		return expect, nil
	}
	worker, err := fortress.Occupy(fix.Guest(c), run, nil)
	c.Assert(err, jc.ErrorIsNil)
	c.Check(worker, gc.Equals, expect)

	// ...and check we can't lockdown again...
	locked := make(chan error, 1)
	go func() {
		locked <- fix.Guard(c).Lockdown(nil)
	}()
	select {
	case err := <-locked:
		c.Fatalf("unexpected Lockdown result: %v", err)
	case <-time.After(coretesting.ShortWait):
	}

	// ...until the worker completes.
	workertest.CleanKill(c, worker)
	select {
	case err := <-locked:
		c.Check(err, jc.ErrorIsNil)
	case <-time.After(coretesting.LongWait):
		c.Fatalf("visit never completed")
	}
}
func newMockBackend() *mockBackend {
	return &mockBackend{
		envWatcher: &mockEnvWatcher{
			Worker:  workertest.NewErrorWorker(nil),
			changes: make(chan []string),
		},
	}
}
Exemplo n.º 4
0
func (s *Suite) TestCheckKilledTimeout(c *gc.C) {
	w := workertest.NewErrorWorker(nil)
	defer workertest.CleanKill(c, w)

	err := workertest.CheckKilled(c, w)
	s.CheckFailed(c)
	c.Check(err, gc.ErrorMatches, "workertest: worker not stopping")
}
Exemplo n.º 5
0
func (s *Suite) TestCheckKillSuccess(c *gc.C) {
	expect := errors.New("fledbon")
	w := workertest.NewErrorWorker(expect)
	defer workertest.DirtyKill(c, w)

	err := workertest.CheckKill(c, w)
	c.Check(err, gc.Equals, expect)
}
Exemplo n.º 6
0
func NewFakeNotifyWatcher() *FakeNotifyWatcher {
	ch := make(chan struct{}, 1)
	ch <- struct{}{}
	return &FakeNotifyWatcher{
		Worker: workertest.NewErrorWorker(nil),
		C:      ch,
	}
}
Exemplo n.º 7
0
func (s *Suite) TestCheckKilledSuccess(c *gc.C) {
	expect := errors.New("snifplog")
	w := workertest.NewErrorWorker(expect)
	defer workertest.DirtyKill(c, w)

	w.Kill()
	err := workertest.CheckKilled(c, w)
	c.Check(err, gc.Equals, expect)
}
Exemplo n.º 8
0
func newStubWatcher() *stubWatcher {
	changes := make(chan []string, 3)
	changes <- []string{"expected", "first"}
	changes <- []string{"expected", "second"}
	changes <- []string{"unexpected?"}
	return &stubWatcher{
		Worker:  workertest.NewErrorWorker(nil),
		changes: changes,
	}
}
Exemplo n.º 9
0
func newStubWatcher() *stubWatcher {
	changes := make(chan struct{}, 3)
	changes <- struct{}{}
	changes <- struct{}{}
	changes <- struct{}{}
	return &stubWatcher{
		Worker:     workertest.NewErrorWorker(nil),
		notifyChan: changes,
	}
}
Exemplo n.º 10
0
// newMockWatcher returns a watcher.NotifyWatcher that always
// sends 3 changes and then sits quietly until killed.
func newMockWatcher() *mockWatcher {
	const count = 3
	changes := make(chan struct{}, count)
	for i := 0; i < count; i++ {
		changes <- struct{}{}
	}
	return &mockWatcher{
		Worker:  workertest.NewErrorWorker(nil),
		changes: changes,
	}
}
Exemplo n.º 11
0
func newStubWatcher(watcherSendInvalidValues bool) *stubWatcher {
	changes := make(chan []string, 3)
	changes <- []string{firstActionID, secondActionID}
	changes <- []string{thirdActionID}
	if watcherSendInvalidValues {
		changes <- []string{"invalid-action-id"}
	}
	return &stubWatcher{
		Worker:  workertest.NewErrorWorker(nil),
		changes: changes,
	}
}
Exemplo n.º 12
0
func (context *context) startPinger() (presence.Pinger, error) {
	context.stub.AddCall("Start")
	context.checkCleanedUp()
	if startErr := context.stub.NextErr(); startErr != nil {
		return nil, startErr
	}

	context.mu.Lock()
	defer context.mu.Unlock()
	pingerErr := context.stub.NextErr()
	context.current = workertest.NewErrorWorker(pingerErr)
	context.starts <- context.current
	return mockPinger{context.current}, nil
}
Exemplo n.º 13
0
func (mock *mockFacade) WatchModelResources() (watcher.NotifyWatcher, error) {
	mock.stub.AddCall("WatchModelResources")
	if err := mock.stub.NextErr(); err != nil {
		return nil, err
	}
	const count = 5
	changes := make(chan struct{}, count)
	for i := 0; i < count; i++ {
		changes <- struct{}{}
	}
	return &mockWatcher{
		Worker:  workertest.NewErrorWorker(nil),
		changes: changes,
	}, nil
}
Exemplo n.º 14
0
// newWorkerList converts the supplied errors into a list of workers to
// be returned in order from the result's Next func (at which point they
// are sent on the reports chan as well).
func newWorkerList(errs []error) *workerList {
	count := len(errs)
	reports := make(chan worker.Worker, count)
	workers := make([]worker.Worker, count)
	for i, err := range errs {
		if err == ErrFailStart {
			workers[i] = nil
		} else {
			workers[i] = workertest.NewErrorWorker(err)
		}
	}
	return &workerList{
		workers: workers,
		reports: reports,
	}
}
Exemplo n.º 15
0
func (*HousingSuite) TestOccupySuccess(c *gc.C) {
	expectWorker := workertest.NewErrorWorker(errors.New("ignored"))
	defer workertest.DirtyKill(c, expectWorker)
	manifold := util.Housing{
		Occupy: "fortress",
	}.Decorate(dependency.Manifold{
		Start: func(dependency.Context) (worker.Worker, error) {
			return expectWorker, nil
		},
	})
	guest := newGuest(true)
	context := dt.StubContext(nil, map[string]interface{}{
		"fortress": guest,
	})

	// wait for the start func to complete
	started := make(chan struct{})
	go func() {
		defer close(started)
		worker, err := manifold.Start(context)
		c.Check(worker, gc.Equals, expectWorker)
		c.Check(err, jc.ErrorIsNil)
	}()
	select {
	case <-started:
	case <-time.After(coretesting.LongWait):
		c.Fatalf("timed out")
	}

	// check the worker's alive
	workertest.CheckAlive(c, expectWorker)

	// check the visit keeps running...
	select {
	case <-time.After(coretesting.ShortWait):
	case <-guest.done:
		c.Fatalf("visit finished early")
	}

	// ...until the worker stops
	expectWorker.Kill()
	select {
	case <-guest.done:
	case <-time.After(coretesting.LongWait):
		c.Fatalf("timed out")
	}
}
Exemplo n.º 16
0
func (*WorkerSuite) TestDeadWaits(c *gc.C) {
	w := workertest.NewErrorWorker(nil)
	defer workertest.CleanKill(c, w)

	dead := worker.Dead(w)
	select {
	case <-time.After(coretesting.ShortWait):
	case _, ok := <-dead:
		if !ok {
			c.Fatalf("Dead closed early")
		} else {
			c.Fatalf("Dead sent unexpectedly")
		}
	}

	w.Kill()
	select {
	case _, ok := <-dead:
		c.Check(ok, jc.IsFalse)
	case <-time.After(coretesting.LongWait):
		c.Fatalf("Dead never closed")
	}
}
Exemplo n.º 17
0
func newMockWatcher(changes chan struct{}) *mockWatcher {
	return &mockWatcher{
		Worker:  workertest.NewErrorWorker(nil),
		changes: changes,
	}
}
Exemplo n.º 18
0
func (s *Suite) TestCleanKillFailure(c *gc.C) {
	w := workertest.NewErrorWorker(errors.New("kebdrix"))

	workertest.CleanKill(c, w)
	s.CheckFailed(c)
}
Exemplo n.º 19
0
func (s *Suite) TestCleanKillSuccess(c *gc.C) {
	w := workertest.NewErrorWorker(nil)

	workertest.CleanKill(c, w)
}
Exemplo n.º 20
0
func newStubWatcher() *stubWatcher {
	return &stubWatcher{
		Worker:  workertest.NewErrorWorker(nil),
		changes: make(chan watcher.MigrationStatus, 1),
	}
}
Exemplo n.º 21
0
func (s *Suite) TestCheckAliveSuccess(c *gc.C) {
	w := workertest.NewErrorWorker(nil)
	defer workertest.CleanKill(c, w)

	workertest.CheckAlive(c, w)
}
Exemplo n.º 22
0
func (s *Suite) TestDirtyKillSuccess(c *gc.C) {
	w := workertest.NewErrorWorker(errors.New("hifstit"))

	workertest.DirtyKill(c, w)
}
Exemplo n.º 23
0
// newNotifyWatcher returns a watcher.NotifyWatcher that will fail with the
// supplied error when Kill()ed.
func newNotifyWatcher(err error) *notifyWatcher {
	return &notifyWatcher{
		Worker:  workertest.NewErrorWorker(err),
		changes: make(chan struct{}, 1000),
	}
}