コード例 #1
0
ファイル: manifold_test.go プロジェクト: snailwalker/juju
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
ファイル: manifold_test.go プロジェクト: kakamessi99/juju
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
ファイル: manifold_test.go プロジェクト: snailwalker/juju
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")
}