diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-10-17 11:32:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-17 11:32:58 +0100 |
commit | 7fec1dc656229386e496dee5dbf15433a706135d (patch) | |
tree | c4b71d85552f47b2d28da5af138904c51cffed1d /test | |
parent | 63d5a1d00e2fdcaa64dae701be7b0cc7221b21df (diff) | |
parent | 82976843d7ce28b4c870495ae1877033c08da3a6 (diff) | |
download | rspamd-7fec1dc656229386e496dee5dbf15433a706135d.tar.gz rspamd-7fec1dc656229386e496dee5dbf15433a706135d.zip |
Merge pull request #2597 from citrin/tests-kill-race-fix
Tests kill race fix
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/lib/rspamd.py | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/test/functional/lib/rspamd.py b/test/functional/lib/rspamd.py index e0454e347..e4462c18c 100644 --- a/test/functional/lib/rspamd.py +++ b/test/functional/lib/rspamd.py @@ -5,14 +5,11 @@ import os.path import psutil import glob import pwd -import re import shutil import signal import socket -import errno import sys import tempfile -import time import subprocess from robot.libraries.BuiltIn import BuiltIn from robot.api import logger @@ -170,34 +167,31 @@ def update_dictionary(a, b): a.update(b) return a -def shutdown_process(process): - i = 0 - while i < 100: - try: - os.kill(process.pid, signal.SIGTERM) - except OSError as e: - assert e.errno == errno.ESRCH - return - if process.status() == psutil.STATUS_ZOMBIE: - return +TERM_TIMEOUT = 10 # wait after sending a SIGTERM signal +KILL_WAIT = 20 # additional wait after sending a SIGKILL signal - i += 1 - time.sleep(0.1) +def shutdown_process(process): + # send SIGTERM + process.terminate() - while i < 200: + try: + process.wait(TERM_TIMEOUT) + return + except psutil.TimeoutExpired: + logger.info( "PID {} is not termianated in {} seconds, sending SIGKILL..." % + (process.pid, TERM_TIMEOUT)) try: - os.kill(process.pid, signal.SIGKILL) - except OSError as e: - assert e.errno == errno.ESRCH + # send SIGKILL + process.kill() + except psutil.NoSuchProcess: + # process exited just befor we tried to kill return - if process.status() == psutil.STATUS_ZOMBIE: - return - - i += 1 - time.sleep(0.1) - assert False, "Failed to shutdown process %d (%s)" % (process.pid, process.name()) + try: + process.wait(KILL_WAIT) + except psutil.TimeoutExpired: + raise RuntimeError("Failed to shutdown process %d (%s)" % (process.pid, process.name())) def shutdown_process_with_children(pid): |