summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2022-04-12 04:16:00 +0100
committerAndrei Zeliankou <zelenkov@nginx.com>2022-04-12 04:16:00 +0100
commit8138d15f76b1017ba61273f69416ffbe028b0d67 (patch)
tree037409185ac445dbf267bb73465b733a5927fb5d /test
parent0f725346603f4de4473d12da502104b188ac02a4 (diff)
downloadunit-8138d15f76b1017ba61273f69416ffbe028b0d67.tar.gz
unit-8138d15f76b1017ba61273f69416ffbe028b0d67.tar.bz2
Tests: added check for zombie processes.
Diffstat (limited to 'test')
-rw-r--r--test/conftest.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/test/conftest.py b/test/conftest.py
index bed56331..904abc32 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -334,6 +334,10 @@ def run(request):
_check_fds(log=log)
+ # check processes id's and amount
+
+ _check_processes()
+
# print unit.log in case of error
if hasattr(request.node, 'rep_call') and request.node.rep_call.failed:
@@ -433,6 +437,16 @@ def unit_stop():
return
+ # check zombies
+
+ out = subprocess.check_output(
+ ['ps', 'ax', '-o', 'state', '-o', 'ppid']
+ ).decode()
+ z_ppids = re.findall(r'Z\s*(\d+)', out)
+ assert unit_instance['pid'] not in z_ppids, 'no zombies'
+
+ # terminate unit
+
p = unit_instance['process']
if p.poll() is not None:
@@ -532,6 +546,50 @@ def _clear_conf(sock, *, log=None):
assert 'success' in resp, 'remove certificate'
+def _check_processes():
+ router_pid = _fds_info['router']['pid']
+ controller_pid = _fds_info['controller']['pid']
+ unit_pid = unit_instance['pid']
+
+ for i in range(600):
+ out = (
+ subprocess.check_output(
+ ['ps', '-ax', '-o', 'pid', '-o', 'ppid', '-o', 'command']
+ )
+ .decode()
+ .splitlines()
+ )
+ out = [l for l in out if unit_pid in l]
+
+ if len(out) <= 3:
+ break
+
+ time.sleep(0.1)
+
+ assert len(out) == 3, 'main, router, and controller expected'
+
+ out = [l for l in out if 'unit: main' not in l]
+ assert len(out) == 2, 'one main'
+
+ out = [
+ l
+ for l in out
+ if re.search(router_pid + r'\s+' + unit_pid + r'.*unit: router', l)
+ is None
+ ]
+ assert len(out) == 1, 'one router'
+
+ out = [
+ l
+ for l in out
+ if re.search(
+ controller_pid + r'\s+' + unit_pid + r'.*unit: controller', l
+ )
+ is None
+ ]
+ assert len(out) == 0, 'one controller'
+
+
@print_log_on_assert
def _check_fds(*, log=None):
def waitforfds(diff):