diff options
author | Andrei Belov <defan@nginx.com> | 2019-11-14 19:29:00 +0300 |
---|---|---|
committer | Andrei Belov <defan@nginx.com> | 2019-11-14 19:29:00 +0300 |
commit | 7630539c44fcb188bba03a65af34e952a81f2f38 (patch) | |
tree | 2c80f0cd315cae8079a39ba98ed89e02b5e1931a /test/unit/main.py | |
parent | 70c9f18b6e8b25850bce8eb1edba4d100c3e55d2 (diff) | |
parent | 0a27f137de776925a24406cf6961c550824c63a0 (diff) | |
download | unit-7630539c44fcb188bba03a65af34e952a81f2f38.tar.gz unit-7630539c44fcb188bba03a65af34e952a81f2f38.tar.bz2 |
Merged with the default branch.1.13.0-1
Diffstat (limited to 'test/unit/main.py')
-rw-r--r-- | test/unit/main.py | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/test/unit/main.py b/test/unit/main.py index 873f1815..094fdb0e 100644 --- a/test/unit/main.py +++ b/test/unit/main.py @@ -185,6 +185,8 @@ class TestUnit(unittest.TestCase): if self._started: self._stop() + self.stop_processes() + def _run(self): self.unitd = self.pardir + '/build/unitd' @@ -240,24 +242,24 @@ class TestUnit(unittest.TestCase): break time.sleep(0.1) - if os.path.exists(self.testdir + '/unit.pid'): - exit("Could not terminate unit") + self._p.join(timeout=5) - self._started = False + if self._p.is_alive(): + self._p.terminate() + self._p.join(timeout=5) - self._p.join(timeout=1) - self._terminate_process(self._p) + if self._p.is_alive(): + self.fail("Could not terminate process " + str(self._p.pid)) - def _terminate_process(self, process): - if process.is_alive(): - process.terminate() - process.join(timeout=5) + if os.path.exists(self.testdir + '/unit.pid'): + self.fail("Could not terminate unit") - if process.is_alive(): - exit("Could not terminate process " + process.pid) + self._started = False - if process.exitcode: - exit("Child process terminated with code " + str(process.exitcode)) + if self._p.exitcode: + self.fail( + "Child process terminated with code " + str(self._p.exitcode) + ) def _check_alerts(self, log): found = False @@ -287,6 +289,26 @@ class TestUnit(unittest.TestCase): if found: print('skipped.') + def run_process(self, target): + if not hasattr(self, '_processes'): + self._processes = [] + + process = Process(target=target) + process.start() + + self._processes.append(process) + + def stop_processes(self): + if not hasattr(self, '_processes'): + return + + for process in self._processes: + process.terminate() + process.join(timeout=5) + + if process.is_alive(): + self.fail('Fail to stop process') + def waitforfiles(self, *files): for i in range(50): wait = False |