Exemplo n.º 1
0
    def test_lost(self):
        beats = []
        lost = []

        def onbeat():
            beats.append('.')

        def onbeatlost():
            lost.append('.')

        hb = Heartbeat('ipc:///tmp/stetho.ipc', interval=0.1)
        hb.start()
        time.sleep(.2)

        stetho = Stethoscope('ipc:///tmp/stetho.ipc', onbeat=onbeat,
                    onbeatlost=onbeatlost,
                    delay=0.1)
        stetho.start()

        time.sleep(2.)
        hb.stop()         # the hber stops

        # the stethoer continues for a while
        time.sleep(2.)

        stetho.stop()

        self.assertTrue(len(beats) > 0)
        self.assertTrue(len(lost) > 3)
Exemplo n.º 2
0
    def test_working(self):
        beats = []
        lost = []

        def onbeat():
            beats.append('.')

        def onbeatlost():
            lost.append('.')

        hb = Heartbeat('ipc:///tmp/stetho.ipc', interval=0.1)
        hb.start()
        time.sleep(.2)

        stetho = Stethoscope('ipc:///tmp/stetho.ipc', onbeat=onbeat,
                    onbeatlost=onbeatlost,
                    delay=0.1)
        stetho.start()

        time.sleep(5.)

        stetho.stop()
        hb.stop()
        self.assertTrue(len(beats) > 10)
        self.assertEqual(len(lost),  0)
Exemplo n.º 3
0
 def __init__(self, target, backend=DEFAULT_BACKEND,
              heartbeat=DEFAULT_HEARTBEAT, ping_delay=1., ping_retries=3,
              params=None, timeout=DEFAULT_TIMEOUT_MOVF,
              max_age=DEFAULT_MAX_AGE, max_age_delta=DEFAULT_MAX_AGE_DELTA):
     logger.debug('Initializing the worker.')
     self.ctx = zmq.Context()
     self.backend = backend
     self._backend = self.ctx.socket(zmq.REP)
     self._backend.connect(self.backend)
     self.target = target
     self.running = False
     self.loop = ioloop.IOLoop()
     self._backstream = zmqstream.ZMQStream(self._backend, self.loop)
     self._backstream.on_recv(self._handle_recv_back)
     self.ping = Stethoscope(heartbeat, onbeatlost=self.lost,
                             delay=ping_delay, retries=ping_retries,
                             ctx=self.ctx)
     self.debug = logger.isEnabledFor(logging.DEBUG)
     self.params = params
     self.pid = os.getpid()
     self.timer = ExecutionTimer(timeout=timeout)
     self.max_age = max_age
     self.max_age_delta = max_age_delta
     self.delayed_exit = None
     self.lock = threading.RLock()
    def test_working(self):
        beats = []
        lost = []

        def onbeat():
            beats.append('.')

        def onbeatlost():
            lost.append('.')

        hb = Heartbeat('ipc:///tmp/stetho.ipc', interval=0.1)
        hb.start()
        time.sleep(.2)

        stetho = Stethoscope('ipc:///tmp/stetho.ipc',
                             onbeat=onbeat,
                             onbeatlost=onbeatlost,
                             delay=1.,
                             retries=5.)
        stetho.start()

        time.sleep(5.)

        stetho.stop()
        hb.stop()
        self.assertEqual(len(lost), 0, len(lost))
        self.assertTrue(len(beats) > 10, len(beats))
    def test_lost(self):
        beats = []
        lost = []

        def _onbeat():
            beats.append('.')

        def _onbeatlost():
            lost.append('.')

        hb = Heartbeat('ipc:///tmp/stetho.ipc', interval=0.1)
        hb.start()
        time.sleep(.2)

        stetho = Stethoscope('ipc:///tmp/stetho.ipc',
                             onbeat=_onbeat,
                             onbeatlost=_onbeatlost,
                             delay=0.1)
        stetho.start()

        time.sleep(2.)
        hb.stop()  # the hber stops

        # the stethoer continues for a while
        time.sleep(2.)

        stetho.stop()

        self.assertTrue(len(beats) > 0)
        self.assertTrue(len(lost) > 3)
Exemplo n.º 6
0
    def test_working(self):
        beats = []
        lost = []

        def onbeat():
            beats.append(".")

        def onbeatlost():
            lost.append(".")

        hb = Heartbeat("ipc:///tmp/stetho.ipc", interval=0.1)
        hb.start()
        time.sleep(0.2)

        stetho = Stethoscope("ipc:///tmp/stetho.ipc", onbeat=onbeat, onbeatlost=onbeatlost, delay=1.0, retries=5.0)
        stetho.start()

        time.sleep(5.0)

        stetho.stop()
        hb.stop()
        self.assertEqual(len(lost), 0, len(lost))
        self.assertTrue(len(beats) > 10, len(beats))