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 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()
res = manageCommand.start()
self.assertEqual(res, 'started')
wait = True
while wait:
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.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: