summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrey Zelenkov <zelenkov@nginx.com>2018-01-10 19:43:44 +0300
committerAndrey Zelenkov <zelenkov@nginx.com>2018-01-10 19:43:44 +0300
commit8546d6d499b9700364bb23b923d022fca10fe00e (patch)
tree5db9c270a23372fc8cd7c22a8f262d693ec93e29
parent138727ec46d98ed6505123e1dfe419b8864ad36f (diff)
downloadunit-8546d6d499b9700364bb23b923d022fca10fe00e.tar.gz
unit-8546d6d499b9700364bb23b923d022fca10fe00e.tar.bz2
Tests: --no-daemon option used for unit.
-rw-r--r--test/unit.py43
1 files changed, 31 insertions, 12 deletions
diff --git a/test/unit.py b/test/unit.py
index 6b567d10..3d331b46 100644
--- a/test/unit.py
+++ b/test/unit.py
@@ -7,7 +7,8 @@ import shutil
import socket
import tempfile
import unittest
-import subprocess
+from subprocess import call
+from multiprocessing import Process
class TestUnit(unittest.TestCase):
@@ -56,18 +57,22 @@ class TestUnit(unittest.TestCase):
os.mkdir(self.testdir + '/state')
- pardir = os.path.abspath(os.path.join(os.path.dirname(__file__),
- os.pardir))
-
print()
- subprocess.call([pardir + '/build/unitd',
- # TODO '--no-daemon',
- '--modules', pardir + '/build',
- '--state', self.testdir + '/state',
- '--pid', self.testdir + '/unit.pid',
- '--log', self.testdir + '/unit.log',
- '--control', 'unix:' + self.testdir + '/control.unit.sock'])
+ def _run_unit():
+ pardir = os.path.abspath(os.path.join(os.path.dirname(__file__),
+ os.pardir))
+
+ call([pardir + '/build/unitd',
+ '--no-daemon',
+ '--modules', pardir + '/build',
+ '--state', self.testdir + '/state',
+ '--pid', self.testdir + '/unit.pid',
+ '--log', self.testdir + '/unit.log',
+ '--control', 'unix:' + self.testdir + '/control.unit.sock'])
+
+ self._p = Process(target=_run_unit)
+ self._p.start()
if not self._waitforfiles(self.testdir + '/unit.pid',
self.testdir + '/unit.log', self.testdir + '/control.unit.sock'):
@@ -77,7 +82,7 @@ class TestUnit(unittest.TestCase):
with open(self.testdir + '/unit.pid', 'r') as f:
pid = f.read().rstrip()
- subprocess.call(['kill', pid])
+ call(['kill', pid])
for i in range(50):
if not os.path.exists(self.testdir + '/unit.pid'):
@@ -87,6 +92,20 @@ class TestUnit(unittest.TestCase):
if os.path.exists(self.testdir + '/unit.pid'):
exit("Could not terminate unit")
+ self._p.join(timeout=1)
+ self._terminate_process(self._p)
+
+ def _terminate_process(self, process):
+ if process.is_alive():
+ process.terminate()
+ process.join(timeout=5)
+
+ if process.is_alive():
+ exit("Could not terminate process " + process.pid)
+
+ if process.exitcode:
+ exit("Child process terminated with code " + str(process.exitcode))
+
def _waitforfiles(self, *files):
for i in range(50):
wait = False