summaryrefslogtreecommitdiffhomepage
path: root/test/unit/main.py
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2020-03-06 20:08:29 +0300
committerValentin Bartenev <vbart@nginx.com>2020-03-06 20:08:29 +0300
commit3617d4ed03326239587b7299370e64669533c6f5 (patch)
treea8189067475821c76e862f022ae88a8b6beaec80 /test/unit/main.py
parent36578c7b43c5872277ba880b28a8a8a237ab7841 (diff)
downloadunit-3617d4ed03326239587b7299370e64669533c6f5.tar.gz
unit-3617d4ed03326239587b7299370e64669533c6f5.tar.bz2
Tests: simplified unitd process running.
There are no reasons to wrap the Unit daemon in a separate Python process.
Diffstat (limited to 'test/unit/main.py')
-rw-r--r--test/unit/main.py68
1 files changed, 26 insertions, 42 deletions
diff --git a/test/unit/main.py b/test/unit/main.py
index 149cfb2c..322066ba 100644
--- a/test/unit/main.py
+++ b/test/unit/main.py
@@ -5,6 +5,7 @@ import stat
import time
import fcntl
import shutil
+import signal
import argparse
import platform
import tempfile
@@ -210,22 +211,19 @@ class TestUnit(unittest.TestCase):
print()
- self._p = Process(target=subprocess.call, args=[ [
- self.unitd,
- '--no-daemon',
- '--modules', self.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.start()
-
- if not self.waitforfiles(
- self.testdir + '/unit.pid',
- self.testdir + '/unit.log',
- self.testdir + '/control.unit.sock',
- ):
+ self._p = subprocess.Popen(
+ [
+ self.unitd,
+ '--no-daemon',
+ '--modules', self.pardir + '/build',
+ '--state', self.testdir + '/state',
+ '--pid', self.testdir + '/unit.pid',
+ '--log', self.testdir + '/unit.log',
+ '--control', 'unix:' + self.testdir + '/control.unit.sock',
+ ]
+ )
+
+ if not self.waitforfiles(self.testdir + '/control.unit.sock'):
exit("Could not start unit")
self._started = True
@@ -238,35 +236,21 @@ class TestUnit(unittest.TestCase):
self.skip_sanitizer = False
def _stop(self):
- with open(self.testdir + '/unit.pid', 'r') as f:
- pid = f.read().rstrip()
-
- subprocess.call(['kill', '-s', 'QUIT', pid])
-
- for i in range(150):
- if not os.path.exists(self.testdir + '/unit.pid'):
- break
- time.sleep(0.1)
-
- self._p.join(timeout=5)
-
- 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")
+ with self._p as p:
+ p.send_signal(signal.SIGQUIT)
+
+ try:
+ retcode = p.wait(15)
+ if retcode:
+ self.fail(
+ "Child process terminated with code " + str(retcode)
+ )
+ except:
+ self.fail("Could not terminate unit")
+ p.kill()
self._started = False
- if self._p.exitcode:
- self.fail(
- "Child process terminated with code " + str(self._p.exitcode)
- )
-
def _check_alerts(self, log):
found = False