Exemplo n.º 1
0
func (s *utilsSuite) TestInitPanic(c *C) {
	s2 := &testService{2, true, false}
	ServiceProvider().Register("a1", s2)
	c.Assert(gorivets.CheckPanic(func() {
		ServiceProvider().Init()
	}), NotNil)
}
Exemplo n.º 2
0
func (s *utilsSuite) TestDoubleInit(c *C) {
	c.Assert(sp.state, Equals, INIT)
	c.Assert(gorivets.CheckPanic(func() {
		ServiceProvider().Init()
		ServiceProvider().Init()
	}), NotNil)
}
Exemplo n.º 3
0
func (s *utilsSuite) TestProvideAfterDestroy(c *C) {
	ServiceProvider().Register("a1", &testService{2, false, false})
	ServiceProvider().Init()
	ServiceProvider().Destroy()
	c.Assert(gorivets.CheckPanic(func() {
		ServiceProvider().Provide("a1")
	}), NotNil)
}
Exemplo n.º 4
0
func (s *utilsSuite) TestDestroyPanic(c *C) {
	s2 := &testService{2, false, true}
	ServiceProvider().Register("a1", s2)
	ServiceProvider().Init()
	c.Assert(gorivets.CheckPanic(func() {
		s2.Destroy()
	}), NotNil)
	ServiceProvider().Destroy()
}
Exemplo n.º 5
0
func (sp *serviceProvider) Destroy() {
	sp.Lock()
	defer sp.Unlock()

	sp.assertState(RUNNING)
	sp.state = DONE

	for i := sp.sortedServices.Len() - 1; i >= 0; i-- {
		s := sp.sortedServices.At(i).(Service)
		if gorivets.CheckPanic(func() {
			s.Destroy()
		}) != nil {
			sp.logger.Warn("Got panic when destroying ", s, " for the priority=", s.Priority())
		} else {
			sp.logger.Info("Destroying service ", s, " for the priority=", s.Priority())
		}
	}
}
Exemplo n.º 6
0
func (s *utilsSuite) TestRegisterAfterInit(c *C) {
	ServiceProvider().Init()
	c.Assert(gorivets.CheckPanic(func() {
		ServiceProvider().Register("a1", &testService{2, false, false})
	}), NotNil)
}