def __init__(self): socket_options = SocketOptions(32768, 16, 32768, 16, 1024000, 1024000) sys_config = {constants.INSTANCE_RECONNECT_STREAMMGR_INTERVAL_SEC: 10} SingleThreadStmgrClient.__init__(self, EventLooper(), None, self.HOST, self.PORT, "topology_name", "topology_id", mock_protobuf.get_mock_instance(), {}, None, socket_options, sys_config) self.register_msg_called = False self.handle_register_response_called = False
def __init__(self): socket_options = SocketOptions(32768, 16, 32768, 16, 1024000, 1024000) with patch( "heron.common.src.python.config.system_config.get_sys_config", side_effect=lambda: {constants.INSTANCE_RECONNECT_STREAMMGR_INTERVAL_SEC: 10}): SingleThreadStmgrClient.__init__(self, EventLooper(), None, self.HOST, self.PORT, "topology_name", "topology_id", mock_protobuf.get_mock_instance(), {}, None, socket_options) self.register_msg_called = False self.handle_register_response_called = False
def __init__(self): socket_options = SocketOptions(32768, 16, 32768, 16, 1024000, 1024000) sys_config = { constants.INSTANCE_RECONNECT_METRICSMGR_INTERVAL_SEC: 10, constants.INSTANCE_METRICS_SYSTEM_SAMPLE_INTERVAL_SEC: 10 } stream = HeronCommunicator(producer_cb=None, consumer_cb=None) MetricsManagerClient.__init__(self, EventLooper(), self.HOST, self.PORT, mock_protobuf.get_mock_instance(), HeronCommunicator(), stream, stream, {}, socket_options, Mock(), sys_config) self.register_req_called = False
def __init__(self): socket_options = SocketOptions(32768, 16, 32768, 16, 1024000, 1024000) with patch( "heron.common.src.python.config.system_config.get_sys_config", side_effect=lambda: { constants.INSTANCE_RECONNECT_METRICSMGR_INTERVAL_SEC: 10, constants.INSTANCE_METRICS_SYSTEM_SAMPLE_INTERVAL_SEC: 10 }): stream = HeronCommunicator(producer_cb=None, consumer_cb=None) MetricsManagerClient.__init__(self, EventLooper(), self.HOST, self.PORT, mock_protobuf.get_mock_instance(), HeronCommunicator(), stream, stream, {}, socket_options, Mock(), Mock()) self.register_req_called = False
def setUp(self): self.looper = EventLooper() self.global_value = 6
class EventLooperTest(unittest.TestCase): def setUp(self): self.looper = EventLooper() self.global_value = 6 def tearDown(self): self.looper = None def test_loop(self): def to_run(): for _ in range(3): self.global_value += 10 self.looper.wake_up() self.looper.exit_loop() self.looper.add_wakeup_task(to_run) self.looper.loop() self.assertEqual(36, self.global_value) def test_add_wakeup_task(self): def to_run(): self.looper.exit_loop() self.global_value = 10 self.looper.add_wakeup_task(to_run) self.looper.loop() self.assertEqual(10, self.global_value) def test_register_timer_task(self): def to_run(): self.looper.exit_loop() self.global_value = 10 start_time = time.time() interval = 1 self.looper.register_timer_task_in_sec(to_run, interval) self.looper.loop() end_time = time.time() self.assertAlmostEqual(start_time + interval, end_time, delta=0.05) self.assertEqual(10, self.global_value) def test_exit_loop(self): def to_run(): self.looper.exit_loop() self.global_value = 10 self.looper.add_wakeup_task(to_run) self.looper.loop() self.assertEqual(10, self.global_value) def test_exit_tasks(self): def exit_task(): self.global_value = 10 def to_run(): self.looper.add_exit_task(exit_task) self.assertEqual(6, self.global_value) self.looper.exit_loop() self.looper.add_wakeup_task(to_run) self.looper.loop() self.assertEqual(10, self.global_value) def test_get_next_timeout_interval(self): to_run = lambda: None interval = 1.0 self.looper.register_timer_task_in_sec(to_run, interval) next_interval = self.looper._get_next_timeout_interval() self.assertAlmostEqual(next_interval, interval, delta=0.01) def test_run_once(self): def to_run(): self.global_value = 10 self.looper.add_wakeup_task(to_run) self.looper._run_once() self.assertEqual(10, self.global_value) def test_trigger_timers(self): def to_run(): self.global_value = 10 interval = 1.0 self.looper.register_timer_task_in_sec(to_run, interval) # run right now, to_run() should not have been executed yet self.looper._trigger_timers() self.assertEqual(6, self.global_value) time.sleep(interval) self.looper._trigger_timers() self.looper._trigger_timers() self.assertEqual(10, self.global_value)