on test, remove sleep and check state of process

This commit is contained in:
AleaJactaEst 2018-02-14 01:46:23 +01:00
parent eddcac1f19
commit 021fe3b7b5

View file

@ -28,7 +28,7 @@ import queue
import signal import signal
import http.server import http.server
import logging import logging
import bcrypt import json
from unittest.mock import patch from unittest.mock import patch
from unittest.mock import MagicMock from unittest.mock import MagicMock
@ -266,6 +266,7 @@ class TestManager(unittest.TestCase):
def test_execute_crash_manager_command(self): def test_execute_crash_manager_command(self):
try: try:
signal.alarm(30)
logsize = 10 logsize = 10
bufsize = 10 bufsize = 10
queueIn = multiprocessing.Queue() queueIn = multiprocessing.Queue()
@ -279,9 +280,14 @@ class TestManager(unittest.TestCase):
queueIn, queueIn,
queueOut, queueOut,
event) event)
manageCommand.start() res = manageCommand.start()
time.sleep(3) self.assertEqual(res, 'started')
manageCommand.status() wait = True
while wait:
time.sleep(1)
res = manageCommand.status()
if res == 'stopped':
wait = False
manageCommand.list_thread() manageCommand.list_thread()
manageCommand.stop() manageCommand.stop()
manageCommand.status() manageCommand.status()
@ -291,6 +297,7 @@ class TestManager(unittest.TestCase):
def test_execute_not_kill_manager_command(self): def test_execute_not_kill_manager_command(self):
try: try:
signal.alarm(30)
logsize = 10 logsize = 10
bufsize = 10 bufsize = 10
queueIn = multiprocessing.Queue() queueIn = multiprocessing.Queue()
@ -305,12 +312,25 @@ class TestManager(unittest.TestCase):
queueOut, queueOut,
event, event,
maxWaitEnd = 2) maxWaitEnd = 2)
manageCommand.start() res = manageCommand.start()
self.assertEqual(res, 'started')
wait = True
while wait:
time.sleep(1) time.sleep(1)
manageCommand.status() 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.list_thread()
manageCommand.stop() manageCommand.stop()
manageCommand.status() res = manageCommand.status()
self.assertEqual(res, 'stopped')
self.assertTrue(True) self.assertTrue(True)
except: except:
self.fail('Error initialize object ManageCommand') self.fail('Error initialize object ManageCommand')
@ -332,9 +352,23 @@ class TestManager(unittest.TestCase):
event, event,
waitDelay = 10) waitDelay = 10)
manageCommand.start() 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() 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() manageCommand.stop()
self.assertTrue(True) self.assertTrue(True)
except: except: