Skip to content

Commit

Permalink
close stdin
Browse files Browse the repository at this point in the history
close stdin

subprocess
  • Loading branch information
jiridanek committed May 26, 2022
1 parent 4e08b64 commit 8635446
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions tests/system_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import re
import shlex
import shutil
import signal
import socket
import subprocess
import sys
Expand Down Expand Up @@ -366,12 +367,16 @@ def error(msg):
try:
self.wait(TIMEOUT)
except TimeoutExpired:
self.kill()
error("did not terminate properly, required kill()")
self.send_signal(signal.SIGABRT) # so that we may get core dump
error("did not terminate properly, required SIGABORT")

# 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 +568,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 8635446

Please sign in to comment.