func (s *PresenceSuite) TestExpiry(c *gc.C) { w := presence.NewWatcher(s.presence) p := presence.NewPinger(s.presence, "a") defer w.Stop() defer p.Stop() ch := make(chan presence.Change) w.Watch("a", ch) assertChange(c, ch, presence.Change{"a", false}) c.Assert(p.Start(), gc.IsNil) w.StartSync() assertChange(c, ch, presence.Change{"a", true}) // Still alive in previous slot. presence.FakeTimeSlot(1) w.StartSync() assertNoChange(c, ch) // Two last slots are empty. presence.FakeTimeSlot(2) w.StartSync() assertChange(c, ch, presence.Change{"a", false}) // Already dead so killing isn't noticed. p.Kill() w.StartSync() assertNoChange(c, ch) }
func (s *PresenceSuite) SetUpTest(c *gc.C) { s.BaseSuite.SetUpTest(c) s.MgoSuite.SetUpTest(c) db := s.MgoSuite.Session.DB("presence") s.presence = db.C("presence") s.pings = db.C("presence.pings") presence.FakeTimeSlot(0) }
func (s *PresenceSuite) TestTwoEnvironments(c *gc.C) { key := "a" w1, p1, ch1 := s.setup(c, key) defer w1.Stop() defer p1.Stop() w2, p2, ch2 := s.setup(c, key) defer w2.Stop() defer p2.Stop() c.Assert(p1.Start(), gc.IsNil) w1.StartSync() w2.StartSync() assertNoChange(c, ch2) assertChange(c, ch1, presence.Change{"a", true}) c.Assert(p2.Start(), gc.IsNil) w1.StartSync() w2.StartSync() assertNoChange(c, ch1) assertChange(c, ch2, presence.Change{"a", true}) err := p1.Kill() c.Assert(err, jc.ErrorIsNil) presence.FakeTimeSlot(1) w1.StartSync() w2.StartSync() assertChange(c, ch1, presence.Change{"a", false}) assertNoChange(c, ch2) err = p2.Kill() c.Assert(err, jc.ErrorIsNil) presence.FakeTimeSlot(2) w1.StartSync() w2.StartSync() assertChange(c, ch2, presence.Change{"a", false}) assertNoChange(c, ch1) }