aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAnton Yuzhaninov <citrin+git@citrin.ru>2018-10-16 11:34:24 -0400
committerAnton Yuzhaninov <citrin+git@citrin.ru>2018-10-16 11:37:59 -0400
commit33016c62b77663561b02c6107285c3689f52208e (patch)
tree33ef1114d92e01e249e1d28feb1af696d5279396 /test
parenta9557341524157ad8960331d4960ea3a7b6ba988 (diff)
downloadrspamd-33016c62b77663561b02c6107285c3689f52208e.tar.gz
rspamd-33016c62b77663561b02c6107285c3689f52208e.zip
[functional test] Fix races in shutdown_process
Currently functional test sometimes fails with and error: Teardown failed: NoSuchProcess: psutil.NoSuchProcess process no longer exists (pid=2259) Rewrite process termination - there is no need to send signals in a loop many times.
Diffstat (limited to 'test')
-rw-r--r--test/functional/lib/rspamd.py41
1 files changed, 19 insertions, 22 deletions
diff --git a/test/functional/lib/rspamd.py b/test/functional/lib/rspamd.py
index e0454e347..5419a115e 100644
--- a/test/functional/lib/rspamd.py
+++ b/test/functional/lib/rspamd.py
@@ -170,34 +170,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):