Make sure all started processed, at least and as a last resort, are killed.

This commit is contained in:
Pedro Algarvio 2016-03-16 18:41:23 +00:00
parent e1281e34cc
commit 2fcc916c6a
No known key found for this signature in database
GPG Key ID: BB36BF6584A298FF

View File

@ -13,6 +13,7 @@ from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../../')
# Import salt libs
import salt.utils
import salt.utils.process
# Import 3rd-party libs
@ -27,6 +28,7 @@ class TestProcessManager(TestCase):
Make sure that the process is alive 2s later
'''
def spin():
salt.utils.appendproctitle('test_basic')
while True:
time.sleep(1)
@ -35,11 +37,21 @@ class TestProcessManager(TestCase):
initial_pid = next(six.iterkeys(process_manager._process_map))
time.sleep(2)
process_manager.check_children()
assert initial_pid == next(six.iterkeys(process_manager._process_map))
process_manager.kill_children()
try:
assert initial_pid == next(six.iterkeys(process_manager._process_map))
finally:
process_manager.stop_restarting()
process_manager.kill_children()
time.sleep(0.5)
# Are there child processes still running?
if process_manager._process_map.keys():
process_manager.send_signal_to_processes(signal.SIGILL)
process_manager.stop_restarting()
process_manager.kill_children()
def test_kill(self):
def spin():
salt.utils.appendproctitle('test_kill')
while True:
time.sleep(1)
@ -51,14 +63,24 @@ class TestProcessManager(TestCase):
# give the OS time to give the signal...
time.sleep(0.1)
process_manager.check_children()
assert initial_pid != next(six.iterkeys(process_manager._process_map))
process_manager.kill_children()
try:
assert initial_pid != next(six.iterkeys(process_manager._process_map))
finally:
process_manager.stop_restarting()
process_manager.kill_children()
time.sleep(0.5)
# Are there child processes still running?
if process_manager._process_map.keys():
process_manager.send_signal_to_processes(signal.SIGILL)
process_manager.stop_restarting()
process_manager.kill_children()
def test_restarting(self):
'''
Make sure that the process is alive 2s later
'''
def die():
salt.utils.appendproctitle('test_restarting')
time.sleep(1)
process_manager = salt.utils.process.ProcessManager()
@ -66,11 +88,21 @@ class TestProcessManager(TestCase):
initial_pid = next(six.iterkeys(process_manager._process_map))
time.sleep(2)
process_manager.check_children()
assert initial_pid != next(six.iterkeys(process_manager._process_map))
process_manager.kill_children()
try:
assert initial_pid != next(six.iterkeys(process_manager._process_map))
finally:
process_manager.stop_restarting()
process_manager.kill_children()
time.sleep(0.5)
# Are there child processes still running?
if process_manager._process_map.keys():
process_manager.send_signal_to_processes(signal.SIGILL)
process_manager.stop_restarting()
process_manager.kill_children()
def test_counter(self):
def incr(counter, num):
salt.utils.appendproctitle('test_counter')
for _ in range(0, num):
counter.value += 1
counter = multiprocessing.Value('i', 0)
@ -80,8 +112,17 @@ class TestProcessManager(TestCase):
process_manager.check_children()
time.sleep(1)
# we should have had 2 processes go at it
assert counter.value == 4
process_manager.kill_children()
try:
assert counter.value == 4
finally:
process_manager.stop_restarting()
process_manager.kill_children()
time.sleep(0.5)
# Are there child processes still running?
if process_manager._process_map.keys():
process_manager.send_signal_to_processes(signal.SIGILL)
process_manager.stop_restarting()
process_manager.kill_children()
class TestThreadPool(TestCase):