Skip to content

Commit

Permalink
Fixes # 415 - Close stdin when tearing down subprocesses in system-te…
Browse files Browse the repository at this point in the history
…sts to prevent fd leaks
  • Loading branch information
jiridanek committed May 26, 2022
1 parent 618e4b3 commit caab4b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions tests/system_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ def error(msg):
# at this point the process has terminated, either of its own accord or
# due to the above terminate call.

# prevent leak of stdin fd
if self.stdin:
self.stdin.close()

if state is None and self.expect != Process.RUNNING:
error("process was unexpectedly still running")

Expand Down Expand Up @@ -563,6 +567,13 @@ def __init__(self, name=None, config=Config(), pyinclude=None, wait=True,
if wait:
self.wait_ready()

def __enter__(self):
"""Allows using the class in the `with` contextmanager"""
return self

def __exit__(self, *_):
self.teardown()

@property
def management(self):
"""Return a management agent proxy for this router"""
Expand Down
4 changes: 2 additions & 2 deletions tests/system_tests_one_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ def test_01_listen_error(self):
config = Qdrouterd.Config([
('router', {'mode': 'standalone', 'id': 'bad'}),
('listener', {'port': OneRouterTest.listen_port})])
r = Qdrouterd(name="expect_fail", config=config, wait=False)
self.assertEqual(1, r.wait())
with Qdrouterd(name="expect_fail", config=config, wait=False, expect=Process.EXIT_FAIL) as r:
self.assertEqual(1, r.wait())

def test_02_pre_settled(self):
addr = self.address + '/closest/' + str(OneRouterTest.closest_count)
Expand Down

0 comments on commit caab4b9

Please sign in to comment.