diff options
author | Mikhail Galanin <mgalanin@mimecast.com> | 2018-08-22 16:00:30 +0100 |
---|---|---|
committer | Mikhail Galanin <mgalanin@mimecast.com> | 2018-08-22 16:00:30 +0100 |
commit | 170a4c4a04208aad1249494321be64e1f7b6c71b (patch) | |
tree | 4b169eb17abb9a90a3c56a5795dac32f0955555c /test/functional/lib/rspamd.py | |
parent | 9ee6b0c059ad291e2e1a3a5cd6f01effd6f115a3 (diff) | |
download | rspamd-170a4c4a04208aad1249494321be64e1f7b6c71b.tar.gz rspamd-170a4c4a04208aad1249494321be64e1f7b6c71b.zip |
[Test] Improved process termination in tests
Diffstat (limited to 'test/functional/lib/rspamd.py')
-rw-r--r-- | test/functional/lib/rspamd.py | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/test/functional/lib/rspamd.py b/test/functional/lib/rspamd.py index 2010f4127..97ab516c1 100644 --- a/test/functional/lib/rspamd.py +++ b/test/functional/lib/rspamd.py @@ -8,11 +8,12 @@ import re import shutil import signal import socket -import string +import errno import sys import tempfile import time from robot.libraries.BuiltIn import BuiltIn +from robot.api import logger if sys.version_info > (3,): long = int @@ -167,32 +168,47 @@ def update_dictionary(a, b): a.update(b) return a -def shutdown_process(pid): +def shutdown_process(process): i = 0 while i < 100: try: - os.kill(pid, signal.SIGTERM) + os.kill(process.pid, signal.SIGTERM) except OSError as e: - assert e.errno == 3 + assert e.errno == errno.ESRCH return + + if process.status() == psutil.STATUS_ZOMBIE: + return + i += 1 time.sleep(0.1) + while i < 200: try: - os.kill(pid, signal.SIGKILL) + os.kill(process.pid, signal.SIGKILL) except OSError as e: - assert e.errno == 3 + assert e.errno == errno.ESRCH return + + if process.status() == psutil.STATUS_ZOMBIE: + return + i += 1 time.sleep(0.1) - assert False, "Failed to shutdown process %s" % pid + assert False, "Failed to shutdown process %d (%s)" % (process.pid, process.name()) + def shutdown_process_with_children(pid): pid = int(pid) - children = psutil.Process(pid=pid).children(recursive=False) - shutdown_process(pid) + try: + process = psutil.Process(pid=pid) + except psutil.NoSuchProcess: + return + children = process.children(recursive=False) + shutdown_process(process) for child in children: try: - shutdown_process(child.pid) + shutdown_process(child) except: pass + |