Ejemplo n.º 1
0
func (s *HookQueueSuite) TestDyingHookQueue(c *gc.C) {
	for i, t := range dyingHookQueueTests {
		c.Logf("test %d: %s", i, t.summary)
		out := make(chan hook.Info)
		q := relation.NewDyingHookQueue(t.initial, out)
		for i, step := range t.steps {
			c.Logf("  step %d", i)
			step.check(c, nil, out)
		}
		expect{}.check(c, nil, out)
		q.Stop()
	}
}
Ejemplo n.º 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
}