tests: Interrupt subprocesses of test_osqueryd (#4032)

This commit is contained in:
Teddy Reed 2018-01-06 00:57:44 -08:00 committed by GitHub
parent ecf06772c8
commit 551e1043b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -665,6 +665,20 @@ class QueryTester(ProcessGenerator, unittest.TestCase):
print(" (%sms) rows: %d" % (duration_ms, len(result)))
class CleanChildProcesses:
# SO: 320232/ensuring-subprocesses-are-dead-on-exiting-python-program
def __enter__(self):
if os.name != "nt":
os.setpgrp()
def __exit__(self, type, value, traceback):
try:
if os.name != "nt":
os.killpg(0, signal.SIGINT)
except KeyboardInterrupt:
# SIGINT is delivered to this process and children.
pass
def expectTrue(functional, interval=0.01, timeout=8):
"""Helper function to run a function with expected latency"""
delay = 0

View File

@ -249,4 +249,5 @@ class DaemonTests(test_base.ProcessGenerator, unittest.TestCase):
daemon.kill()
if __name__ == '__main__':
test_base.Tester().run()
with test_base.CleanChildProcesses():
test_base.Tester().run()