Beispiel #1
0
func (s *Suite) TestCheckKillTimeout(c *gc.C) {
	w := workertest.NewForeverWorker(nil)
	defer w.ReallyKill()

	err := workertest.CheckKill(c, w)
	s.CheckFailed(c)
	c.Check(err, gc.ErrorMatches, "workertest: worker not stopping")
}
Beispiel #2
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)
}
Beispiel #3
0
func (s *suite) TestStartStop(c *gc.C) {
	if runtime.GOOS != "linux" {
		c.Skip("introspection worker not supported on non-linux")
	}

	w, err := introspection.NewWorker(introspection.Config{
		SocketName: "introspection-test",
	})
	c.Assert(err, jc.ErrorIsNil)
	workertest.CheckKill(c, w)
}
Beispiel #4
0
func (s *introspectionSuite) startWorker(c *gc.C) {
	s.name = fmt.Sprintf("introspection-test-%d", os.Getpid())
	w, err := introspection.NewWorker(introspection.Config{
		SocketName: s.name,
		Reporter:   s.reporter,
	})
	c.Assert(err, jc.ErrorIsNil)
	s.worker = w
	s.AddCleanup(func(c *gc.C) {
		workertest.CheckKill(c, w)
	})
}
Beispiel #5
0
func (s *LogForwarderSuite) checkClose(c *gc.C, lf worker.Worker, expected error) {
	go func() {
		s.sender.waitBeforeClose(c)
	}()
	var err error
	if expected == nil {
		workertest.CleanKill(c, lf)
	} else {
		err = workertest.CheckKill(c, lf)
	}
	c.Check(errors.Cause(err), gc.Equals, expected)
	s.stub.CheckCallNames(c, "Close")
}
Beispiel #6
0
func (s *introspectionSuite) TestEngineReporter(c *gc.C) {
	// We need to make sure the existing worker is shut down
	// so we can connect to the socket.
	workertest.CheckKill(c, s.worker)
	s.reporter = &reporter{
		values: map[string]interface{}{
			"working": true,
		},
	}
	s.startWorker(c)
	buf := s.call(c, "/depengine/")

	matches(c, buf, "200 OK")
	matches(c, buf, "working: true")
}
Beispiel #7
0
func (*DumbWorkersSuite) TestLeadershipManagerFails(c *gc.C) {
	fix := BasicFixture()
	fix.LW_errors = []error{errors.New("zap")}
	fix.RunDumb(c, func(ctx Context, dw *workers.DumbWorkers) {
		w := NextWorker(c, ctx.LWs())
		c.Assert(w, gc.NotNil)
		AssertWorker(c, dw.LeadershipManager(), w)

		w.Kill()
		workertest.CheckAlive(c, dw)
		AssertWorker(c, dw.LeadershipManager(), w)

		err := workertest.CheckKill(c, dw)
		c.Check(err, gc.ErrorMatches, "error stopping leadership lease manager: zap")
	})
}
Beispiel #8
0
func (*DumbWorkersSuite) TestTxnLogWatcherFails(c *gc.C) {
	fix := BasicFixture()
	fix.TLW_errors = []error{errors.New("zap")}
	fix.RunDumb(c, func(ctx Context, dw *workers.DumbWorkers) {
		w := NextWorker(c, ctx.TLWs())
		c.Assert(w, gc.NotNil)
		AssertWorker(c, dw.TxnLogWatcher(), w)

		w.Kill()
		workertest.CheckAlive(c, dw)
		AssertWorker(c, dw.TxnLogWatcher(), w)

		err := workertest.CheckKill(c, dw)
		c.Check(err, gc.ErrorMatches, "error stopping transaction log watcher: zap")
	})
}
Beispiel #9
0
func (s *ManifoldsSuite) TestClockWrapper(c *gc.C) {
	expectClock := &fakeClock{}
	manifolds := model.Manifolds(model.ManifoldsConfig{
		Agent: &mockAgent{},
		Clock: expectClock,
	})
	manifold, ok := manifolds["clock"]
	c.Assert(ok, jc.IsTrue)
	worker, err := manifold.Start(nil)
	c.Assert(err, jc.ErrorIsNil)
	defer workertest.CheckKill(c, worker)

	var clock clock.Clock
	err = manifold.Output(worker, &clock)
	c.Assert(err, jc.ErrorIsNil)
	c.Check(clock, gc.Equals, expectClock)
}
Beispiel #10
0
func (*RestartWorkersSuite) TestLeadershipManagerDelay(c *gc.C) {
	fix := BasicFixture()
	fix.LW_errors = []error{errors.New("oof")}
	fix.RunRestart(c, func(ctx Context, rw *workers.RestartWorkers) {
		w := NextWorker(c, ctx.LWs())
		c.Assert(w, gc.NotNil)
		AssertWorker(c, rw.LeadershipManager(), w)
		w.Kill()

		clock := ctx.Clock()
		WaitAlarms(c, clock, 1)
		clock.Advance(almostFiveSeconds)
		AssertWorker(c, rw.LeadershipManager(), w)

		err := workertest.CheckKill(c, rw)
		c.Check(err, gc.ErrorMatches, "error stopping leadership lease manager: oof")
	})
}
Beispiel #11
0
func (*DumbWorkersSuite) TestEverythingFails(c *gc.C) {
	fix := Fixture{
		LW_errors:  []error{errors.New("zot")},
		SW_errors:  []error{errors.New("bif")},
		TLW_errors: []error{errors.New("pow")},
		PW_errors:  []error{errors.New("arg")},
	}
	fix.RunDumb(c, func(ctx Context, dw *workers.DumbWorkers) {
		for _, ch := range []<-chan worker.Worker{
			ctx.LWs(), ctx.SWs(), ctx.TLWs(), ctx.PWs(),
		} {
			w := NextWorker(c, ch)
			c.Assert(w, gc.NotNil)
			w.Kill()
		}

		workertest.CheckAlive(c, dw)
		err := workertest.CheckKill(c, dw)
		c.Check(err, gc.ErrorMatches, "error stopping transaction log watcher: pow")
	})
}