mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-07 09:58:54 +00:00
tests: Interrupt subprocesses of test_osqueryd (#4032)
This commit is contained in:
parent
ecf06772c8
commit
551e1043b4
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user