Beispiel #1
0
 def test_running_start(self):
     with closing(asyncevent.EventLoop()) as loop:
         lc = asyncutils.LoopingCall(loop, loop.stop)
         lc.start(0.1)
         with self.assertRaises(AssertionError):
             lc.start(0.1)
         loop.run_forever()
Beispiel #2
0
    def test_callback_args(self):
        with closing(asyncevent.EventLoop()) as loop:
            log = []

            def cb(*args):
                log.append(args)
                loop.stop()

            lc = asyncutils.LoopingCall(loop, cb, "a", "b")
            lc.start(0.1)
            loop.run_forever()

        print("calls:", log, end=" ")
        self.assertEqual(log, [("a", "b")])
Beispiel #3
0
    def test_stop(self):
        with closing(asyncevent.EventLoop()) as loop:
            log = []

            def cb():
                log.append((loop.time(), lc.deadline))
                lc.stop()

            lc = asyncutils.LoopingCall(loop, cb)
            lc.start(0.1)
            loop.call_later(0.2, loop.stop)
            loop.run_forever()

        print("calls:", log, end=" ")
        self.assertEqual(len(log), 1)
Beispiel #4
0
    def test_continue_after_errors(self):
        with closing(asyncevent.EventLoop()) as loop:
            log = []

            def cb():
                log.append((loop.time(), lc.deadline))
                raise RuntimeError("Callback failed!")

            lc = asyncutils.LoopingCall(loop, cb)
            with self.assertRaises(RuntimeError):
                lc.start(0.1)
            loop.call_later(0.15, loop.stop)
            loop.run_forever()

        print("calls:", log, end=" ")
        self.assertEqual(len(log), 2)
Beispiel #5
0
    def test_loop(self):
        with closing(asyncevent.EventLoop()) as loop:
            log = []

            def cb():
                log.append((loop.time(), lc.deadline))

            lc = asyncutils.LoopingCall(loop, cb)
            lc.start(0.1)
            loop.call_later(0.45, loop.stop)
            loop.run_forever()

        print("calls:", log, end=" ")
        self.assertEqual(len(log), 5)
        for call_time, expected_time in log:
            self.assertAlmostEqual(call_time, expected_time, delta=0.01)
Beispiel #6
0
    def test_slow_callback(self):
        with closing(asyncevent.EventLoop()) as loop:
            log = []

            def cb():
                log.append((loop.time(), lc.deadline))
                # Miss the next deadline
                time.sleep(0.1)

            lc = asyncutils.LoopingCall(loop, cb)
            lc.start(0.1)
            loop.call_later(0.45, loop.stop)
            loop.run_forever()

        # Expected calls:
        # 0.00 ok
        # 0.10 miss
        # 0.20 ok
        # 0.30 miss
        # 0.40 ok
        # 0.45 stop
        print("calls:", log, end=" ")

        self.assertEqual(len(log), 3)
Beispiel #7
0
 def __init__(self):
     self._lock = threading.Lock()
     self._loop = asyncevent.EventLoop()
     self._thread = concurrent.thread(self._loop.run_forever,
                                      name="check/loop")
     self._checkers = {}
Beispiel #8
0
 def setUp(self):
     self.loop = asyncevent.EventLoop()
     self.thread = concurrent.thread(self.loop.run_forever)
     self.thread.start()
     self.completed = threading.Event()
Beispiel #9
0
 def setUp(self):
     self.loop = asyncevent.EventLoop()
     self.results = []
     self.checks = 1
Beispiel #10
0
 def setUp(self):
     self.loop = asyncevent.EventLoop()
     self.rc = None
Beispiel #11
0
 def setUp(self):
     self.loop = asyncevent.EventLoop()
     self.received = None
Beispiel #12
0
 def setup_method(self, m):
     self.loop = asyncevent.EventLoop()
     self.results = []
     self.checks = 1
Beispiel #13
0
 def setup_method(self):
     self.loop = asyncevent.EventLoop()
     self.results = []
Beispiel #14
0
 def setup_method(self, m):
     self.loop = asyncevent.EventLoop()
     self.rc = None