def test_start_heartbeat(self, mocked_init, mocked_Logger, mocked_Profiler): rmq_params = mock.MagicMock(spec=ConnectionParameters) rmgr = mock.MagicMock(spec=Base_ResourceManager) tmgr = Tmgr('test_tmgr', ['pending_queues'], ['completed_queues'], rmgr, rmq_params, 'test_rts') global_boolean = False def _heartbeat_side_effect(): nonlocal global_boolean global_boolean = True tmgr._log = mocked_Logger tmgr._prof = mocked_Profiler tmgr._heartbeat = mock.MagicMock(side_effect=_heartbeat_side_effect) tmgr._uid = 'tmgr.0000' tmgr._hb_terminate = None tmgr._hb_thread = None tmgr.start_heartbeat() try: self.assertTrue(global_boolean) self.assertIsInstance(tmgr._hb_terminate, mt.Event) self.assertIsInstance(tmgr._hb_thread, mt.Thread) finally: if tmgr._hb_thread.is_alive(): tmgr._hb_thread.join()
def test_tmgr_base_terminate_heartbeat(): credentials = pika.PlainCredentials(username, password) rmq_conn_params = pika.ConnectionParameters(host=hostname, port=port, credentials=credentials) sid = 'test.0005' rmgr = BaseRmgr({}, sid, None, {}) tmgr = BaseTmgr(sid=sid, pending_queue=['pending-1'], completed_queue=['completed-1'], rmgr=rmgr, rmq_conn_params=rmq_conn_params, rts=None) tmgr._hb_terminate = mt.Event() assert tmgr.start_heartbeat() assert not tmgr._hb_terminate.is_set() assert tmgr._hb_thread.is_alive() tmgr.terminate_heartbeat() time.sleep(5) assert not tmgr._hb_thread assert tmgr._hb_terminate.is_set()
def test_tmgr_base_start_heartbeat(): sid = 'test.0004' rmgr = BaseRmgr({}, sid, None, {}) tmgr = BaseTmgr(sid=sid, pending_queue=['pending-1'], completed_queue=['completed-1'], rmgr=rmgr, mq_hostname=hostname, port=port, rts=None) assert tmgr.start_heartbeat() assert not tmgr._hb_terminate.is_set() assert tmgr._hb_thread.is_alive() tmgr._hb_terminate.set() time.sleep(15) tmgr._hb_thread.join() assert not tmgr._hb_thread.is_alive()
def test_tmgr_base_start_heartbeat(): rmq_conn_params = pika.ConnectionParameters(host=hostname, port=port) sid = 'test.0004' rmgr = BaseRmgr({}, sid, None, {}) tmgr = BaseTmgr(sid=sid, pending_queue=['pending-1'], completed_queue=['completed-1'], rmgr=rmgr, rmq_conn_params=rmq_conn_params, rts=None) assert tmgr.start_heartbeat() assert not tmgr._hb_terminate.is_set() assert tmgr._hb_thread.is_alive() tmgr._hb_terminate.set() time.sleep(15) tmgr._hb_thread.join() assert not tmgr._hb_thread.is_alive()
def test_tmgr_base_start_heartbeat(): sid = 'test.0000' rmgr = BaseRmgr({}, sid, None, {}) os.environ['ENTK_HB_INTERVAL'] = '30' tmgr = BaseTmgr(sid=sid, pending_queue=['pending-1'], completed_queue=['completed-1'], rmgr=rmgr, mq_hostname=hostname, port=port, rts=None) assert tmgr.start_heartbeat() assert not tmgr._hb_terminate.is_set() assert tmgr._hb_thread.is_alive() tmgr._hb_terminate.set() sleep(15) tmgr._hb_thread.join() assert not tmgr._hb_thread.is_alive()
def test_tmgr_base_terminate_heartbeat(): sid = 'test.0000' rmgr = BaseRmgr({}, sid, None, {}) os.environ['ENTK_HB_INTERVAL'] = '30' tmgr = BaseTmgr(sid=sid, pending_queue=['pending-1'], completed_queue=['completed-1'], rmgr=rmgr, mq_hostname=hostname, port=port, rts=None) tmgr._hb_terminate = threading.Event() assert tmgr.start_heartbeat() assert not tmgr._hb_terminate.is_set() assert tmgr._hb_thread.is_alive() tmgr.terminate_heartbeat() sleep(30) assert not tmgr._hb_thread assert tmgr._hb_terminate.is_set()