def start_test(self): timer = select_connection._Timer() poller = select_connection.SelectPoller( get_wait_seconds=timer.get_remaining_interval, process_timeouts=timer.process_timeouts) self.addCleanup(poller.close) timer_call_container = [] timer.call_later(0.00001, lambda: timer_call_container.append(1)) poller.poll() delay = poller._get_wait_seconds() self.assertIsNotNone(delay) deadline = time.time() + delay while True: poller._process_timeouts() if time.time() < deadline: self.assertEqual(timer_call_container, []) else: # One last time in case deadline reached after previous # processing cycle poller._process_timeouts() break self.assertEqual(timer_call_container, [1])
def _create_select_poller_connection_impl(parameters, on_open_callback, on_open_error_callback, on_close_callback, stop_ioloop_on_close): """Used for disabling autochoise of poller ('select', 'poll', 'epool', etc) inside default 'SelectConnection.__init__(...)' logic. It is necessary to force 'select' poller usage if eventlet is monkeypatched because eventlet patches only 'select' system call Method signature is copied form 'SelectConnection.__init__(...)', because it is used as replacement of 'SelectConnection' class to create instances """ return select_connection.SelectConnection( parameters=parameters, on_open_callback=on_open_callback, on_open_error_callback=on_open_error_callback, on_close_callback=on_close_callback, stop_ioloop_on_close=stop_ioloop_on_close, custom_ioloop=select_connection.SelectPoller())
def start_test(self): poller = select_connection.SelectPoller() timer_call_container = [] poller.add_timeout(0.00001, lambda: timer_call_container.append(1)) poller.poll() deadline = poller._next_timeout while True: poller.process_timeouts() if time.time() < deadline: self.assertEqual(timer_call_container, []) else: # One last time in case deadline reached after previous # processing cycle poller.process_timeouts() break self.assertEqual(timer_call_container, [1])