summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2020-03-23 02:12:44 +0000
committerAndrei Zeliankou <zelenkov@nginx.com>2020-03-23 02:12:44 +0000
commitc7cc247baa2f9b6cd2499416644adf0bd13ff070 (patch)
tree906f92fc38fd35679b5b53a0eb8f39742639f6ed /test
parent59e06e49101ef0eba3c4c9e351c23fa56e2137d8 (diff)
downloadunit-c7cc247baa2f9b6cd2499416644adf0bd13ff070.tar.gz
unit-c7cc247baa2f9b6cd2499416644adf0bd13ff070.tar.bz2
Tests: terminate unitd process on exit().
Diffstat (limited to '')
-rw-r--r--test/unit/main.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/test/unit/main.py b/test/unit/main.py
index 69234dcc..a1182e5c 100644
--- a/test/unit/main.py
+++ b/test/unit/main.py
@@ -4,6 +4,7 @@ import sys
import stat
import time
import fcntl
+import atexit
import shutil
import signal
import argparse
@@ -188,10 +189,9 @@ class TestUnit(unittest.TestCase):
self._print_log()
def stop(self):
- if self._started:
- self._stop()
-
+ self._stop()
self.stop_processes()
+ atexit.unregister(self.stop)
def _run(self):
build_dir = self.pardir + '/build'
@@ -224,11 +224,11 @@ class TestUnit(unittest.TestCase):
stderr=log,
)
+ atexit.register(self.stop)
+
if not self.waitforfiles(self.testdir + '/control.unit.sock'):
exit("Could not start unit")
- self._started = True
-
self.skip_alerts = [
r'read signalfd\(4\) failed',
r'last message send failed',
@@ -238,6 +238,9 @@ class TestUnit(unittest.TestCase):
self.skip_sanitizer = False
def _stop(self):
+ if self._p.poll() is not None:
+ return
+
with self._p as p:
p.send_signal(signal.SIGQUIT)
@@ -248,10 +251,8 @@ class TestUnit(unittest.TestCase):
"Child process terminated with code " + str(retcode)
)
except:
- self.fail("Could not terminate unit")
p.kill()
-
- self._started = False
+ self.fail("Could not terminate unit")
def _check_alerts(self, log):
found = False
@@ -295,11 +296,12 @@ class TestUnit(unittest.TestCase):
return
for process in self._processes:
- process.terminate()
- process.join(timeout=5)
-
if process.is_alive():
- self.fail('Fail to stop process')
+ process.terminate()
+ process.join(timeout=15)
+
+ if process.is_alive():
+ self.fail('Fail to stop process')
def waitforfiles(self, *files):
for i in range(50):