Exemplo n.º 1
0
// StartHooks starts watching the relation, and sending hook.Info events on the
// hooks channel. It will panic if called when already responding to relation
// changes.
func (r *Relationer) StartHooks() {
	if r.IsImplicit() {
		return
	}
	if r.queue != nil {
		panic("hooks already started!")
	}
	if r.dying {
		r.queue = relation.NewDyingHookQueue(r.dir.State(), r.hooks)
	} else {
		r.queue = relation.NewAliveHookQueue(r.dir.State(), r.hooks, r.ru.Watch())
	}
}
Exemplo n.º 2
0
func (s *HookQueueSuite) TestAliveHookQueue(c *C) {
	for i, t := range aliveHookQueueTests {
		c.Logf("test %d: %s", i, t.summary)
		out := make(chan hook.Info)
		in := make(chan state.RelationUnitsChange)
		ruw := &RUW{in, false}
		q := relation.NewAliveHookQueue(t.initial, out, ruw)
		for i, step := range t.steps {
			c.Logf("  step %d", i)
			step.check(c, in, out)
		}
		expect{}.check(c, in, out)
		q.Stop()
		c.Assert(ruw.stopped, Equals, true)
	}
}