Example #1
0
func (s *HookQueueSuite) TestAliveHookQueue(c *gc.C) {
	for i, t := range aliveHookQueueTests {
		c.Logf("test %d: %s", i, t.summary)
		out := make(chan hook.Info)
		in := make(chan params.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, gc.Equals, true)
	}
}
Example #2
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() error {
	if r.IsImplicit() {
		return nil
	}
	if r.queue != nil {
		panic("hooks already started!")
	}
	if r.dying {
		r.queue = relation.NewDyingHookQueue(r.dir.State(), r.hooks)
	} else {
		w, err := r.ru.Watch()
		if err != nil {
			return err
		}
		r.queue = relation.NewAliveHookQueue(r.dir.State(), r.hooks, w)
	}
	return nil
}