From 021fe3b7b52c6b352b752ebfcfebbbe5f6255740 Mon Sep 17 00:00:00 2001 From: AleaJactaEst Date: Wed, 14 Feb 2018 01:46:23 +0100 Subject: [PATCH] on test, remove sleep and check state of process --- tests/test_manager.py | 54 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/tests/test_manager.py b/tests/test_manager.py index 28e8463..8ac1e46 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -28,7 +28,7 @@ import queue import signal import http.server import logging -import bcrypt +import json from unittest.mock import patch from unittest.mock import MagicMock @@ -266,6 +266,7 @@ class TestManager(unittest.TestCase): def test_execute_crash_manager_command(self): try: + signal.alarm(30) logsize = 10 bufsize = 10 queueIn = multiprocessing.Queue() @@ -279,9 +280,14 @@ class TestManager(unittest.TestCase): queueIn, queueOut, event) - manageCommand.start() - time.sleep(3) - manageCommand.status() + res = manageCommand.start() + self.assertEqual(res, 'started') + wait = True + while wait: + time.sleep(1) + res = manageCommand.status() + if res == 'stopped': + wait = False manageCommand.list_thread() manageCommand.stop() manageCommand.status() @@ -291,6 +297,7 @@ class TestManager(unittest.TestCase): def test_execute_not_kill_manager_command(self): try: + signal.alarm(30) logsize = 10 bufsize = 10 queueIn = multiprocessing.Queue() @@ -305,12 +312,25 @@ class TestManager(unittest.TestCase): queueOut, event, maxWaitEnd = 2) - manageCommand.start() - time.sleep(1) - manageCommand.status() + res = manageCommand.start() + self.assertEqual(res, 'started') + wait = True + while wait: + time.sleep(1) + res = manageCommand.status() + self.assertEqual(res, 'started') + res = manageCommand.getlog(0) + try: + resjson = json.loads(res) + if 'last-line' in res: + if resjson['last-line'] == 3: + wait = False + except: + pass manageCommand.list_thread() manageCommand.stop() - manageCommand.status() + res = manageCommand.status() + self.assertEqual(res, 'stopped') self.assertTrue(True) except: self.fail('Error initialize object ManageCommand') @@ -332,9 +352,23 @@ class TestManager(unittest.TestCase): event, waitDelay = 10) manageCommand.start() - time.sleep(5) + wait = True + while wait: + time.sleep(1) + res = manageCommand.status() + if res == 'stopped': + wait = False + res = manageCommand.status() + self.assertEqual(res, 'stopped') manageCommand.start() - time.sleep(5) + wait = True + while wait: + time.sleep(1) + res = manageCommand.status() + if res == 'stopped': + wait = False + res = manageCommand.status() + self.assertEqual(res, 'stopped') manageCommand.stop() self.assertTrue(True) except: