Use the new cleanup helper for process cleanup
This removes some repetition of logic and switches to a more aggressive cleanup approach.
This commit is contained in:
parent
cec31e6e5a
commit
e511adbf63
|
@ -6,6 +6,7 @@ from time import sleep
|
||||||
from os import mkdir, listdir
|
from os import mkdir, listdir
|
||||||
from os.path import join, exists
|
from os.path import join, exists
|
||||||
from tempfile import mkdtemp, mktemp
|
from tempfile import mkdtemp, mktemp
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
from twisted.python.procutils import which
|
from twisted.python.procutils import which
|
||||||
from twisted.internet.error import (
|
from twisted.internet.error import (
|
||||||
|
@ -23,6 +24,7 @@ from util import (
|
||||||
_ProcessExitedProtocol,
|
_ProcessExitedProtocol,
|
||||||
_create_node,
|
_create_node,
|
||||||
_run_node,
|
_run_node,
|
||||||
|
_cleanup_twistd_process,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,11 +109,7 @@ def flog_gatherer(reactor, temp_dir, flog_binary, request):
|
||||||
pytest_twisted.blockon(twistd_protocol.magic_seen)
|
pytest_twisted.blockon(twistd_protocol.magic_seen)
|
||||||
|
|
||||||
def cleanup():
|
def cleanup():
|
||||||
try:
|
_cleanup_twistd_process(twistd_process, twistd_protocol.exited)
|
||||||
twistd_process.signalProcess('TERM')
|
|
||||||
pytest_twisted.blockon(twistd_protocol.exited)
|
|
||||||
except ProcessExitedAlready:
|
|
||||||
pass
|
|
||||||
|
|
||||||
flog_file = mktemp('.flog_dump')
|
flog_file = mktemp('.flog_dump')
|
||||||
flog_protocol = _DumpOutputProtocol(open(flog_file, 'w'))
|
flog_protocol = _DumpOutputProtocol(open(flog_file, 'w'))
|
||||||
|
@ -180,14 +178,7 @@ log_gatherer.furl = {log_furl}
|
||||||
intro_dir,
|
intro_dir,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
request.addfinalizer(partial(_cleanup_twistd_process, process, protocol.exited))
|
||||||
def cleanup():
|
|
||||||
try:
|
|
||||||
process.signalProcess('TERM')
|
|
||||||
pytest_twisted.blockon(protocol.exited)
|
|
||||||
except ProcessExitedAlready:
|
|
||||||
pass
|
|
||||||
request.addfinalizer(cleanup)
|
|
||||||
|
|
||||||
pytest_twisted.blockon(protocol.magic_seen)
|
pytest_twisted.blockon(protocol.magic_seen)
|
||||||
return process
|
return process
|
||||||
|
|
|
@ -3,6 +3,7 @@ import time
|
||||||
from os import mkdir
|
from os import mkdir
|
||||||
from os.path import exists, join
|
from os.path import exists, join
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
from twisted.internet.defer import Deferred, succeed
|
from twisted.internet.defer import Deferred, succeed
|
||||||
from twisted.internet.protocol import ProcessProtocol
|
from twisted.internet.protocol import ProcessProtocol
|
||||||
|
@ -144,13 +145,7 @@ def _run_node(reactor, node_dir, request, magic_text):
|
||||||
)
|
)
|
||||||
process.exited = protocol.exited
|
process.exited = protocol.exited
|
||||||
|
|
||||||
def cleanup():
|
request.addfinalizer(partial(_cleanup_twistd_process, process, protocol.exited))
|
||||||
try:
|
|
||||||
process.signalProcess('TERM')
|
|
||||||
pytest_twisted.blockon(protocol.exited)
|
|
||||||
except ProcessExitedAlready:
|
|
||||||
pass
|
|
||||||
request.addfinalizer(cleanup)
|
|
||||||
|
|
||||||
# we return the 'process' ITransport instance
|
# we return the 'process' ITransport instance
|
||||||
# XXX abusing the Deferred; should use .when_magic_seen() or something?
|
# XXX abusing the Deferred; should use .when_magic_seen() or something?
|
||||||
|
|
Loading…
Reference in New Issue