From 8717445b8311afe7c6782d10aed2e292034aabb8 Mon Sep 17 00:00:00 2001 From: Qiu Tingting Date: Fri, 2 Apr 2021 13:30:04 +0800 Subject: Add testcase of get_extra_info and kill_process api to taskmanager service module. Bug-AGL: SPEC-3946 Signed-off-by: Qiu Tingting Change-Id: Id9cb3e3df6f6c13c95acfa0875f708ed98fb29f6 --- pyagl/services/taskmanager.py | 20 ++++++++++++++++++++ pyagl/tests/test_taskmanager.py | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/pyagl/services/taskmanager.py b/pyagl/services/taskmanager.py index 388b931..488094e 100644 --- a/pyagl/services/taskmanager.py +++ b/pyagl/services/taskmanager.py @@ -26,6 +26,8 @@ class TaskManagerService(AGLBaseService): parser.add_argument('--get_process_list', action='store_true') parser.add_argument('--get_netstat', action='store_true') parser.add_argument('--get_load_avg', action='store_true') + parser.add_argument('--get_extra_info', help='unique process ID', type=int) + parser.add_argument('--kill_process', help='unique process ID', type=int) def __init__(self, ip, port=None, service='agl-service-taskmanager'): super().__init__(api='taskmanager', ip=ip, port=port, service=service) @@ -39,6 +41,12 @@ class TaskManagerService(AGLBaseService): async def get_netstat(self): return await self.request('get_netstat') + async def kill_process(self, tid=None): + return await self.request('kill_process', tid) + + async def get_extra_info(self, tid=None): + return await self.request('get_extra_info', tid) + async def agent_response(self): pass @@ -64,6 +72,18 @@ async def main(loop): resp = await tasks.afbresponse() print(resp.data) + if args.get_extra_info: + msgid = await tasks.get_extra_info(args.get_extra_info) + print(f'Sent tid={args.get_extra_info} request with messageid {msgid}') + resp = await tasks.afbresponse() + print(resp) + + if args.kill_process: + msgid = await tasks.kill_process(args.kill_process) + print(f'Sent tid={args.kill_process} request with messageid {msgid}') + resp = await tasks.afbresponse() + print(resp) + if args.listener: for response in nets.listener(): print(response) diff --git a/pyagl/tests/test_taskmanager.py b/pyagl/tests/test_taskmanager.py index 10c1855..fc1f489 100644 --- a/pyagl/tests/test_taskmanager.py +++ b/pyagl/tests/test_taskmanager.py @@ -21,6 +21,12 @@ import logging from pyagl.services.base import AFBResponse, AFBT from pyagl.services.taskmanager import TaskManagerService as TASK +import multiprocessing +import time + +def action(max): + time.sleep(max) + pytestmark = [pytest.mark.asyncio, pytest.mark.taskmanager] @pytest.fixture(scope='module') @@ -52,3 +58,21 @@ async def test_get_load_avg(event_loop, service: TASK): msgid = await service.get_load_avg() resp = await service.afbresponse() assert resp.status == 'success' + +@pytest.mark.xfail(reason='Tests that are known to fail, until the agl-service-taskmanager is fixed in master.') +async def test_get_extra_info(event_loop, service: TASK): + msgid = await service.get_extra_info(1) + resp = await service.afbresponse() + assert resp.status == 'success' + +async def test_kill_process(event_loop, service: TASK): + mp1 = multiprocessing.Process(target=action,args=(10,)) + mp1.start() + time.sleep(3) + print(f'process id: '+str(mp1.pid)) + msgid = await service.kill_process(mp1.pid) + resp = await service.afbresponse() + assert resp.status == 'not-replied' + time.sleep(1) + assert mp1.is_alive() == False + -- cgit 1.2.3-korg