Tests: --no-daemon option used for unit.

This commit is contained in:
Andrey Zelenkov
2018-01-10 19:43:44 +03:00
parent 138727ec46
commit 8546d6d499

View File

@@ -7,7 +7,8 @@ import shutil
import socket import socket
import tempfile import tempfile
import unittest import unittest
import subprocess from subprocess import call
from multiprocessing import Process
class TestUnit(unittest.TestCase): class TestUnit(unittest.TestCase):
@@ -56,19 +57,23 @@ class TestUnit(unittest.TestCase):
os.mkdir(self.testdir + '/state') os.mkdir(self.testdir + '/state')
print()
def _run_unit():
pardir = os.path.abspath(os.path.join(os.path.dirname(__file__), pardir = os.path.abspath(os.path.join(os.path.dirname(__file__),
os.pardir)) os.pardir))
print() call([pardir + '/build/unitd',
'--no-daemon',
subprocess.call([pardir + '/build/unitd',
# TODO '--no-daemon',
'--modules', pardir + '/build', '--modules', pardir + '/build',
'--state', self.testdir + '/state', '--state', self.testdir + '/state',
'--pid', self.testdir + '/unit.pid', '--pid', self.testdir + '/unit.pid',
'--log', self.testdir + '/unit.log', '--log', self.testdir + '/unit.log',
'--control', 'unix:' + self.testdir + '/control.unit.sock']) '--control', 'unix:' + self.testdir + '/control.unit.sock'])
self._p = Process(target=_run_unit)
self._p.start()
if not self._waitforfiles(self.testdir + '/unit.pid', if not self._waitforfiles(self.testdir + '/unit.pid',
self.testdir + '/unit.log', self.testdir + '/control.unit.sock'): self.testdir + '/unit.log', self.testdir + '/control.unit.sock'):
exit("Could not start unit") exit("Could not start unit")
@@ -77,7 +82,7 @@ class TestUnit(unittest.TestCase):
with open(self.testdir + '/unit.pid', 'r') as f: with open(self.testdir + '/unit.pid', 'r') as f:
pid = f.read().rstrip() pid = f.read().rstrip()
subprocess.call(['kill', pid]) call(['kill', pid])
for i in range(50): for i in range(50):
if not os.path.exists(self.testdir + '/unit.pid'): 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'): if os.path.exists(self.testdir + '/unit.pid'):
exit("Could not terminate unit") 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): def _waitforfiles(self, *files):
for i in range(50): for i in range(50):
wait = False wait = False