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

View File

@ -28,6 +28,12 @@ from allmydata import client
import pytest_twisted 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): class _ProcessExitedProtocol(ProcessProtocol):
""" """
Internal helper that .callback()s on self.done when the process 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. :return: After the process has exited.
""" """
from twisted.internet import reactor
try: try:
print("signaling {} with TERM".format(tahoe_transport.pid)) print("signaling {} with TERM".format(tahoe_transport.pid))
tahoe_transport.signalProcess('TERM') tahoe_transport.signalProcess('TERM')
print("signaled, blocking on exit") print("signaled, blocking on exit")
pytest_twisted.blockon(exited) block_with_timeout(exited, reactor)
print("exited, goodbye") print("exited, goodbye")
except ProcessExitedAlready: except ProcessExitedAlready:
pass pass