Beispiel #1
0
func (s *KillSuite) TestKillWaitForModels_AllGood(c *gc.C) {
	s.resetAPIModels(c)
	wrapped, inner := s.newKillCommandBoth()
	err := coretesting.InitCommand(wrapped, []string{"test1", "--timeout=1m"})
	c.Assert(err, jc.ErrorIsNil)

	ctx := coretesting.Context(c)
	err = controller.KillWaitForModels(inner, ctx, s.api, test1UUID)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(coretesting.Stderr(ctx), gc.Equals, "All hosted models reclaimed, cleaning up controller machines\n")
}
Beispiel #2
0
func (s *KillSuite) TestKillWaitForModels_TimeoutResetsWithChange(c *gc.C) {
	s.resetAPIModels(c)
	s.addModel("model-1", base.ModelStatus{
		UUID:               test2UUID,
		Life:               string(params.Dying),
		Owner:              "admin",
		HostedMachineCount: 2,
		ServiceCount:       2,
	})
	wrapped, inner := s.newKillCommandBoth()
	err := coretesting.InitCommand(wrapped, []string{"test1", "--timeout=20s"})
	c.Assert(err, jc.ErrorIsNil)

	ctx := coretesting.Context(c)
	result := make(chan error)
	go func() {
		err := controller.KillWaitForModels(inner, ctx, s.api, test1UUID)
		result <- err
	}()

	s.syncClockAlarm(c)
	s.clock.Advance(5 * time.Second)

	s.syncClockAlarm(c)
	s.setModelStatus(base.ModelStatus{
		UUID:               test2UUID,
		Life:               string(params.Dying),
		Owner:              "admin",
		HostedMachineCount: 1,
	})
	s.clock.Advance(5 * time.Second)

	s.syncClockAlarm(c)
	s.removeModel(test2UUID)
	s.clock.Advance(5 * time.Second)

	select {
	case err := <-result:
		c.Assert(err, jc.ErrorIsNil)
	case <-time.After(coretesting.LongWait):
		c.Fatal("timed out waiting for result")
	}
	expect := "" +
		"Waiting on 1 model, 2 machines, 2 applications, will kill machines directly in 20s\n" +
		"Waiting on 1 model, 2 machines, 2 applications, will kill machines directly in 15s\n" +
		"Waiting on 1 model, 1 machine, will kill machines directly in 20s\n" +
		"All hosted models reclaimed, cleaning up controller machines\n"

	c.Assert(coretesting.Stderr(ctx), gc.Equals, expect)
}