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()
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")])
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)
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)
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)
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)
def __init__(self): self._lock = threading.Lock() self._loop = asyncevent.EventLoop() self._thread = concurrent.thread(self._loop.run_forever, name="check/loop") self._checkers = {}
def setUp(self): self.loop = asyncevent.EventLoop() self.thread = concurrent.thread(self.loop.run_forever) self.thread.start() self.completed = threading.Event()
def setUp(self): self.loop = asyncevent.EventLoop() self.results = [] self.checks = 1
def setUp(self): self.loop = asyncevent.EventLoop() self.rc = None
def setUp(self): self.loop = asyncevent.EventLoop() self.received = None
def setup_method(self, m): self.loop = asyncevent.EventLoop() self.results = [] self.checks = 1
def setup_method(self): self.loop = asyncevent.EventLoop() self.results = []
def setup_method(self, m): self.loop = asyncevent.EventLoop() self.rc = None