def test_terminate_manager(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') tmgr._log = mocked_Logger tmgr._prof = mocked_Profiler tmgr._uid = 'tmgr.0000' tmgr._tmgr_terminate = mp.Event() tmgr._tmgr_process = mp.Process(target=_tmgr_side_effect, name='test_tmgr', args=(tmgr._tmgr_terminate, )) tmgr._tmgr_process.start() pid = tmgr._tmgr_process.pid tmgr.check_manager = mock.MagicMock(return_value=True) tmgr.terminate_manager() self.assertIsNone(tmgr._tmgr_process) self.assertFalse(psutil.pid_exists(pid))
def test_tmgr_base_check_manager(): sid = 'test.0000' 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) tmgr._tmgr_process = Process(target=tmgr._tmgr, name='heartbeat') tmgr._tmgr_terminate = Event() tmgr._tmgr_process.start() assert tmgr.check_manager() tmgr.terminate_manager()
def test_tmgr_base_check_manager(): rmq_conn_params = pika.ConnectionParameters(host=hostname, port=port) sid = 'test.0008' 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._tmgr_process = mp.Process(target=tmgr._tmgr, name='heartbeat') tmgr._tmgr_terminate = mp.Event() tmgr._tmgr_process.start() assert tmgr.check_manager() tmgr.terminate_manager()
def test_tmgr_base_terminate_manager(): credentials = pika.PlainCredentials(username, password) rmq_conn_params = pika.ConnectionParameters(host=hostname, port=port, credentials=credentials) sid = 'test.0006' 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._tmgr_process = mp.Process(target=tmgr._tmgr, name='heartbeat') tmgr._tmgr_terminate = mp.Event() tmgr.terminate_manager() assert not tmgr._tmgr_process assert tmgr._tmgr_terminate.is_set()