diff options
author | Andrey Zelenkov <zelenkov@nginx.com> | 2017-12-06 15:35:28 +0300 |
---|---|---|
committer | Andrey Zelenkov <zelenkov@nginx.com> | 2017-12-06 15:35:28 +0300 |
commit | 7ae5bef233d744f514427a33e1da531040d3fd6f (patch) | |
tree | 1bf4ddf1dcfc1d888fdc0c7a21b2f0fe3d3fb37b /test/unit.py | |
parent | 79b1d4f5ff664cba84108fd124d78362949faa99 (diff) | |
download | unit-7ae5bef233d744f514427a33e1da531040d3fd6f.tar.gz unit-7ae5bef233d744f514427a33e1da531040d3fd6f.tar.bz2 |
Tests: check_modules() function introduced.
Diffstat (limited to 'test/unit.py')
-rw-r--r-- | test/unit.py | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/test/unit.py b/test/unit.py index b8cd5154..0857272e 100644 --- a/test/unit.py +++ b/test/unit.py @@ -12,6 +12,45 @@ import subprocess class TestUnit(unittest.TestCase):
def setUp(self):
+ self._run()
+
+ def tearDown(self):
+ self._stop()
+
+ if '--log' in sys.argv:
+ with open(self.testdir + '/unit.log', 'r') as f:
+ print(f.read())
+
+ if '--leave' not in sys.argv:
+ shutil.rmtree(self.testdir)
+
+ def check_modules(self, *modules):
+ self._run()
+
+ for i in range(50):
+ with open(self.testdir + '/unit.log', 'r') as f:
+ log = f.read()
+ m = re.search('controller started', log, re.M | re.S)
+
+ if m is None:
+ time.sleep(0.1)
+ else:
+ break
+
+ if m is None:
+ exit("Unit is writing log too long")
+
+ ret = ''
+ for module in modules:
+ m = re.search('module: ' + module, log, re.M | re.S)
+ if m is None:
+ ret = module
+
+ self._stop()
+
+ return ret
+
+ def _run(self):
self.testdir = tempfile.mkdtemp(prefix='unit-test-')
os.mkdir(self.testdir + '/state')
@@ -33,9 +72,7 @@ class TestUnit(unittest.TestCase): self.testdir + '/unit.log', self.testdir + '/control.unit.sock'):
exit("Could not start unit")
- # TODO dependency check
-
- def tearDown(self):
+ def _stop(self):
with open(self.testdir + '/unit.pid', 'r') as f:
pid = f.read().rstrip()
@@ -49,13 +86,6 @@ class TestUnit(unittest.TestCase): if os.path.exists(self.testdir + '/unit.pid'):
exit("Could not terminate unit")
- if '--log' in sys.argv:
- with open(self.testdir + '/unit.log', 'r') as f:
- print(f.read())
-
- if '--leave' not in sys.argv:
- shutil.rmtree(self.testdir)
-
def _waitforfiles(self, *files):
for i in range(50):
wait = False
|