Пример #1
0
func (s *PatchedManifoldSuite) TestStatusWorkerDoesNotRerunAfterRestart(c *gc.C) {
	getResource := dt.StubGetResource(s.dummyResources)
	worker, err := s.manifold.Start(getResource)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(worker, gc.NotNil)

	s.msClient.changes <- struct{}{}

	// Kill worker.
	worker.Kill()
	err = worker.Wait()
	c.Assert(err, jc.ErrorIsNil)

	// Restart it.
	worker, err = s.manifold.Start(getResource)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(worker, gc.NotNil)

	running := make(chan struct{})
	meterstatus.PatchInit(worker, func() { close(running) })

	select {
	case <-running:
	case <-time.After(coretesting.LongWait):
		c.Fatal("timed out waiting for signal")
	}

	worker.Kill()
	err = worker.Wait()

	s.stub.CheckCallNames(c, "MeterStatus", "RunHook", "WatchMeterStatus", "MeterStatus", "MeterStatus", "WatchMeterStatus")
	c.Assert(err, jc.ErrorIsNil)
}
Пример #2
0
func (s *ManifoldSuite) TestStatusWorkerRunsHookOnChanges(c *gc.C) {
	msClient := &stubMeterStatusClient{stub: s.stub, changes: make(chan struct{})}
	s.PatchValue(meterstatus.NewMeterStatusClient,
		func(_ base.APICaller, _ names.UnitTag) msapi.MeterStatusClient {
			return msClient
		})
	s.PatchValue(meterstatus.NewRunner,
		func(_ runner.Context, _ context.Paths) runner.Runner {
			return &stubRunner{stub: s.stub}
		})

	getResource := dt.StubGetResource(s.dummyResources)

	worker, err := s.manifold.Start(getResource)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(worker, gc.NotNil)

	running := make(chan struct{})
	meterstatus.PatchInit(worker, func() { close(running) })

	select {
	case <-running:
	case <-time.After(coretesting.LongWait):
		c.Fatal("timed out waiting for signal")
	}
	msClient.changes <- struct{}{}
	msClient.code = "RED"

	worker.Kill()
	err = worker.Wait()
	c.Assert(err, jc.ErrorIsNil)
	s.stub.CheckCallNames(c, "MeterStatus", "RunHook", "WatchMeterStatus", "MeterStatus", "RunHook")

}
Пример #3
0
func (s *PatchedManifoldSuite) TestStatusWorkerHandlesRandomHookError(c *gc.C) {
	s.stub.SetErrors(fmt.Errorf("blah"))

	getResource := dt.StubGetResource(s.dummyResources)

	worker, err := s.manifold.Start(getResource)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(worker, gc.NotNil)

	running := make(chan struct{})
	meterstatus.PatchInit(worker, func() { close(running) })

	select {
	case <-running:
	case <-time.After(coretesting.LongWait):
		c.Fatal("timed out waiting for signal")
	}

	worker.Kill()
	err = worker.Wait()
	c.Assert(err, jc.ErrorIsNil)
	s.stub.CheckCallNames(c, "MeterStatus", "RunHook", "WatchMeterStatus")
}