Exemple #1
0
 def test_start_when_disabled(self):
     timer = MockTimer()
     eventer = MockDispatcher()
     eventer.enabled = False
     h = Heart(timer, eventer)
     h.start()
     self.assertFalse(h.tref)
 def test_start_when_disabled(self):
     timer = MockTimer()
     eventer = MockDispatcher()
     eventer.enabled = False
     h = Heart(timer, eventer)
     h.start()
     self.assertFalse(h.tref)
 def test_stop(self):
     timer = MockTimer()
     eventer = MockDispatcher()
     h = Heart(timer, eventer, interval=1)
     h.start()
     self.assertTrue(h.tref)
     h.stop()
     self.assertIsNone(h.tref)
 def test_start_stop(self):
     timer = MockTimer()
     eventer = MockDispatcher()
     h = Heart(timer, eventer, interval=1)
     h.start()
     assert h.tref
     h.stop()
     assert h.tref is None
     h.stop()
 def test_start_stop(self):
     timer = MockTimer()
     eventer = MockDispatcher()
     h = Heart(timer, eventer, interval=1)
     h.start()
     assert h.tref
     h.stop()
     assert h.tref is None
     h.stop()
 def test_run_manages_cycle(self):
     eventer = MockDispatcher()
     heart = Heart(MockTimer(), eventer, interval=0.1)
     eventer.heart = heart
     heart.start()
     msecs, fun, args, kwargs = tref = heart.tref
     self.assertEqual(msecs, 0.1 * 1000)
     self.assertEqual(tref.fun, eventer.send)
     self.assertTrue(tref.args)
     self.assertTrue(tref.kwargs)
     heart.stop()
     self.assertTrue(tref.cancelled)
Exemple #7
0
    def test_message_retries(self):
        timer = MockTimer()
        eventer = MockDispatcher()
        eventer.enabled = True
        h = Heart(timer, eventer, interval=1)

        h.start()
        assert eventer.sent[-1][0] == "worker-online"

        # Invoke a heartbeat
        h.tref[1](*h.tref[2], **h.tref[3])
        assert eventer.sent[-1][0] == "worker-heartbeat"
        assert eventer.sent[-1][1]["retry"]

        h.stop()
        assert eventer.sent[-1][0] == "worker-offline"
        assert not eventer.sent[-1][1]["retry"]