mirror of
https://github.com/chatmail/relay.git
synced 2026-05-21 13:28:05 +00:00
fix a potential hang because "journalctl -f" never finishes by itself, and handles might stay open if we don't close them during test teardown.
This commit is contained in:
@@ -487,13 +487,16 @@ def cmfactory(
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def remote(sshdomain, pytestconfig):
|
def remote(sshdomain, pytestconfig):
|
||||||
return Remote(sshdomain, ssh_config=pytestconfig.getoption("ssh_config"))
|
r = Remote(sshdomain, ssh_config=pytestconfig.getoption("ssh_config"))
|
||||||
|
yield r
|
||||||
|
r.close()
|
||||||
|
|
||||||
|
|
||||||
class Remote:
|
class Remote:
|
||||||
def __init__(self, sshdomain, ssh_config=None):
|
def __init__(self, sshdomain, ssh_config=None):
|
||||||
self.sshdomain = sshdomain
|
self.sshdomain = sshdomain
|
||||||
self.ssh_config = ssh_config
|
self.ssh_config = ssh_config
|
||||||
|
self._procs = []
|
||||||
|
|
||||||
def iter_output(self, logcmd="", ready=None):
|
def iter_output(self, logcmd="", ready=None):
|
||||||
getjournal = "journalctl -f" if not logcmd else logcmd
|
getjournal = "journalctl -f" if not logcmd else logcmd
|
||||||
@@ -509,12 +512,14 @@ class Remote:
|
|||||||
command.extend(["-F", self.ssh_config])
|
command.extend(["-F", self.ssh_config])
|
||||||
command.append(f"root@{self.sshdomain}")
|
command.append(f"root@{self.sshdomain}")
|
||||||
[command.append(arg) for arg in getjournal.split()]
|
[command.append(arg) for arg in getjournal.split()]
|
||||||
self.popen = subprocess.Popen(
|
popen = subprocess.Popen(
|
||||||
command,
|
command,
|
||||||
|
stdin=subprocess.DEVNULL,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
)
|
)
|
||||||
|
self._procs.append(popen)
|
||||||
while 1:
|
while 1:
|
||||||
line = self.popen.stdout.readline()
|
line = popen.stdout.readline()
|
||||||
res = line.decode().strip().lower()
|
res = line.decode().strip().lower()
|
||||||
if not res:
|
if not res:
|
||||||
break
|
break
|
||||||
@@ -523,6 +528,12 @@ class Remote:
|
|||||||
ready = None
|
ready = None
|
||||||
yield res
|
yield res
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
while self._procs:
|
||||||
|
proc = self._procs.pop()
|
||||||
|
proc.kill()
|
||||||
|
proc.wait()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def lp(request):
|
def lp(request):
|
||||||
|
|||||||
Reference in New Issue
Block a user