Infinite blocking is bad.

This commit is contained in:
Itamar Turner-Trauring 2021-01-12 13:58:28 -05:00
parent b74ec6919d
commit dfcd75f20d
2 changed files with 13 additions and 5 deletions

View File

@ -40,7 +40,8 @@ from util import (
TahoeProcess,
cli,
_run_node,
generate_ssh_key
generate_ssh_key,
block_with_timeout,
)
@ -156,7 +157,7 @@ def flog_gatherer(reactor, temp_dir, flog_binary, request):
)
print("Waiting for flogtool to complete")
try:
pytest_twisted.blockon(flog_protocol.done)
block_with_timeout(flog_protocol.done, reactor)
except ProcessTerminated as e:
print("flogtool exited unexpectedly: {}".format(str(e)))
print("Flogtool completed")
@ -297,7 +298,7 @@ log_gatherer.furl = {log_furl}
def cleanup():
try:
transport.signalProcess('TERM')
pytest_twisted.blockon(protocol.exited)
block_with_timeout(protocol.exited, reactor)
except ProcessExitedAlready:
pass
request.addfinalizer(cleanup)
@ -537,7 +538,7 @@ def tor_network(reactor, temp_dir, chutney, request):
env=env,
)
try:
pytest_twisted.blockon(proto.done)
block_with_timeout(proto.done, reactor)
except ProcessTerminated:
# If this doesn't exit cleanly, that's fine, that shouldn't fail
# the test suite.

View File

@ -28,6 +28,12 @@ from allmydata import client
import pytest_twisted
def block_with_timeout(deferred, reactor, timeout=10):
"""Block until Deferred has result, but timeout instead of waiting forever."""
deferred.addTimeout(timeout, reactor)
return pytest_twisted.blockon(deferred)
class _ProcessExitedProtocol(ProcessProtocol):
"""
Internal helper that .callback()s on self.done when the process
@ -126,11 +132,12 @@ def _cleanup_tahoe_process(tahoe_transport, exited):
:return: After the process has exited.
"""
from twisted.internet import reactor
try:
print("signaling {} with TERM".format(tahoe_transport.pid))
tahoe_transport.signalProcess('TERM')
print("signaled, blocking on exit")
pytest_twisted.blockon(exited)
block_with_timeout(exited, reactor)
print("exited, goodbye")
except ProcessExitedAlready:
pass