Tests: terminate unitd process on exit().
This commit is contained in:
@@ -4,6 +4,7 @@ import sys
|
|||||||
import stat
|
import stat
|
||||||
import time
|
import time
|
||||||
import fcntl
|
import fcntl
|
||||||
|
import atexit
|
||||||
import shutil
|
import shutil
|
||||||
import signal
|
import signal
|
||||||
import argparse
|
import argparse
|
||||||
@@ -188,10 +189,9 @@ class TestUnit(unittest.TestCase):
|
|||||||
self._print_log()
|
self._print_log()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
if self._started:
|
self._stop()
|
||||||
self._stop()
|
|
||||||
|
|
||||||
self.stop_processes()
|
self.stop_processes()
|
||||||
|
atexit.unregister(self.stop)
|
||||||
|
|
||||||
def _run(self):
|
def _run(self):
|
||||||
build_dir = self.pardir + '/build'
|
build_dir = self.pardir + '/build'
|
||||||
@@ -224,11 +224,11 @@ class TestUnit(unittest.TestCase):
|
|||||||
stderr=log,
|
stderr=log,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
atexit.register(self.stop)
|
||||||
|
|
||||||
if not self.waitforfiles(self.testdir + '/control.unit.sock'):
|
if not self.waitforfiles(self.testdir + '/control.unit.sock'):
|
||||||
exit("Could not start unit")
|
exit("Could not start unit")
|
||||||
|
|
||||||
self._started = True
|
|
||||||
|
|
||||||
self.skip_alerts = [
|
self.skip_alerts = [
|
||||||
r'read signalfd\(4\) failed',
|
r'read signalfd\(4\) failed',
|
||||||
r'last message send failed',
|
r'last message send failed',
|
||||||
@@ -238,6 +238,9 @@ class TestUnit(unittest.TestCase):
|
|||||||
self.skip_sanitizer = False
|
self.skip_sanitizer = False
|
||||||
|
|
||||||
def _stop(self):
|
def _stop(self):
|
||||||
|
if self._p.poll() is not None:
|
||||||
|
return
|
||||||
|
|
||||||
with self._p as p:
|
with self._p as p:
|
||||||
p.send_signal(signal.SIGQUIT)
|
p.send_signal(signal.SIGQUIT)
|
||||||
|
|
||||||
@@ -248,10 +251,8 @@ class TestUnit(unittest.TestCase):
|
|||||||
"Child process terminated with code " + str(retcode)
|
"Child process terminated with code " + str(retcode)
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
self.fail("Could not terminate unit")
|
|
||||||
p.kill()
|
p.kill()
|
||||||
|
self.fail("Could not terminate unit")
|
||||||
self._started = False
|
|
||||||
|
|
||||||
def _check_alerts(self, log):
|
def _check_alerts(self, log):
|
||||||
found = False
|
found = False
|
||||||
@@ -295,11 +296,12 @@ class TestUnit(unittest.TestCase):
|
|||||||
return
|
return
|
||||||
|
|
||||||
for process in self._processes:
|
for process in self._processes:
|
||||||
process.terminate()
|
|
||||||
process.join(timeout=5)
|
|
||||||
|
|
||||||
if process.is_alive():
|
if process.is_alive():
|
||||||
self.fail('Fail to stop process')
|
process.terminate()
|
||||||
|
process.join(timeout=15)
|
||||||
|
|
||||||
|
if process.is_alive():
|
||||||
|
self.fail('Fail to stop process')
|
||||||
|
|
||||||
def waitforfiles(self, *files):
|
def waitforfiles(self, *files):
|
||||||
for i in range(50):
|
for i in range(50):
|
||||||
|
|||||||
Reference in New Issue
Block a user