Tests: simplified unitd process running.
There are no reasons to wrap the Unit daemon in a separate Python process.
This commit is contained in:
@@ -5,6 +5,7 @@ import stat
|
|||||||
import time
|
import time
|
||||||
import fcntl
|
import fcntl
|
||||||
import shutil
|
import shutil
|
||||||
|
import signal
|
||||||
import argparse
|
import argparse
|
||||||
import platform
|
import platform
|
||||||
import tempfile
|
import tempfile
|
||||||
@@ -210,22 +211,19 @@ class TestUnit(unittest.TestCase):
|
|||||||
|
|
||||||
print()
|
print()
|
||||||
|
|
||||||
self._p = Process(target=subprocess.call, args=[ [
|
self._p = subprocess.Popen(
|
||||||
self.unitd,
|
[
|
||||||
'--no-daemon',
|
self.unitd,
|
||||||
'--modules', self.pardir + '/build',
|
'--no-daemon',
|
||||||
'--state', self.testdir + '/state',
|
'--modules', self.pardir + '/build',
|
||||||
'--pid', self.testdir + '/unit.pid',
|
'--state', self.testdir + '/state',
|
||||||
'--log', self.testdir + '/unit.log',
|
'--pid', self.testdir + '/unit.pid',
|
||||||
'--control', 'unix:' + self.testdir + '/control.unit.sock',
|
'--log', self.testdir + '/unit.log',
|
||||||
] ])
|
'--control', 'unix:' + self.testdir + '/control.unit.sock',
|
||||||
self._p.start()
|
]
|
||||||
|
)
|
||||||
|
|
||||||
if not self.waitforfiles(
|
if not self.waitforfiles(self.testdir + '/control.unit.sock'):
|
||||||
self.testdir + '/unit.pid',
|
|
||||||
self.testdir + '/unit.log',
|
|
||||||
self.testdir + '/control.unit.sock',
|
|
||||||
):
|
|
||||||
exit("Could not start unit")
|
exit("Could not start unit")
|
||||||
|
|
||||||
self._started = True
|
self._started = True
|
||||||
@@ -238,35 +236,21 @@ class TestUnit(unittest.TestCase):
|
|||||||
self.skip_sanitizer = False
|
self.skip_sanitizer = False
|
||||||
|
|
||||||
def _stop(self):
|
def _stop(self):
|
||||||
with open(self.testdir + '/unit.pid', 'r') as f:
|
with self._p as p:
|
||||||
pid = f.read().rstrip()
|
p.send_signal(signal.SIGQUIT)
|
||||||
|
|
||||||
subprocess.call(['kill', '-s', 'QUIT', pid])
|
try:
|
||||||
|
retcode = p.wait(15)
|
||||||
for i in range(150):
|
if retcode:
|
||||||
if not os.path.exists(self.testdir + '/unit.pid'):
|
self.fail(
|
||||||
break
|
"Child process terminated with code " + str(retcode)
|
||||||
time.sleep(0.1)
|
)
|
||||||
|
except:
|
||||||
self._p.join(timeout=5)
|
self.fail("Could not terminate unit")
|
||||||
|
p.kill()
|
||||||
if self._p.is_alive():
|
|
||||||
self._p.terminate()
|
|
||||||
self._p.join(timeout=5)
|
|
||||||
|
|
||||||
if self._p.is_alive():
|
|
||||||
self.fail("Could not terminate process " + str(self._p.pid))
|
|
||||||
|
|
||||||
if os.path.exists(self.testdir + '/unit.pid'):
|
|
||||||
self.fail("Could not terminate unit")
|
|
||||||
|
|
||||||
self._started = False
|
self._started = False
|
||||||
|
|
||||||
if self._p.exitcode:
|
|
||||||
self.fail(
|
|
||||||
"Child process terminated with code " + str(self._p.exitcode)
|
|
||||||
)
|
|
||||||
|
|
||||||
def _check_alerts(self, log):
|
def _check_alerts(self, log):
|
||||||
found = False
|
found = False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user