Exemple #1
0
    def test_start_stop(self):
        self.loop = loop = LoopingCall(self.looper, 1, hats=True)

        loop.start(1)
        loop.stop()

        with self.condition:
            if not self.calls:
                self.condition.wait(5)

        self.assertEqual(self.calls, 1)
        self.assertLastPassed(1, hats=True)
Exemple #2
0
    def test_error_caught(self):
        self.loop = LoopingCall(self.looper)
        self.raise_this = Exception("too many sandwiches")

        self.loop.start(0)

        with self.condition:
            while not self.calls >= 3:

                self.condition.wait()

        self.loop.stop()
        self.assertGreaterEqual(self.calls, 3)
Exemple #3
0
    def start(self):
        log.info('EPUAgent starting')

        self.dashi.handle(self.heartbeat)

        self.loop = LoopingCall(self._loop)
        if self.start_beat:
            log.debug('Starting heartbeat loop - %s second interval',
                      self.period)
            self.loop.start(self.period)

        try:
            self.dashi.consume()
        except KeyboardInterrupt:
            log.warning("Caught terminate signal. Exiting")
        else:
            log.info("Exiting normally.")
Exemple #4
0
    def test_called(self):
        # looper will stop itself after 3 calls
        self.max_calls = 3
        self.loop = loop = LoopingCall(self.looper, 1, 2, anarg=5)

        # interval of 0 makes it not block
        loop.start(0)
        self.assertTrue(self.stopped.wait(5))

        #peek into looping call and join on thread
        thread = loop.thread
        if thread:
            thread.join()

        self.assertFalse(loop.running)
        self.assertEqual(self.calls, 3)
        self.assertPassed(0, 1, 2, anarg=5)
        self.assertPassed(1, 1, 2, anarg=5)
        self.assertPassed(2, 1, 2, anarg=5)
Exemple #5
0
    def test_start_stop_2(self):
        self.loop = loop = LoopingCall(self.looper, 1, hats=True)

        loop.start(1, now=False)
        loop.stop()
        self.assertEqual(self.calls, 0)