factor cleanup into api class

This commit is contained in:
Jean-Paul Calderone 2019-05-03 07:27:58 -04:00
parent 5a1183500e
commit 57fc078383
2 changed files with 21 additions and 16 deletions

View File

@ -26,7 +26,12 @@ from twisted.internet.defer import (
succeed,
)
from allmydata.client import _Client
from ..client import (
_Client,
)
from ..scripts.tahoe_stop import (
COULD_NOT_STOP,
)
class Expect(Protocol):
def __init__(self):
@ -134,6 +139,20 @@ class CLINodeAPI(object):
# the test fails), the client should still terminate.
self.exit_trigger_file.touch()
def cleanup(self):
stopping = stop_and_wait(tahoe)
stopping.addErrback(
# Let it fail because the process has already exited.
lambda err: (
err.trap(ProcessTerminated)
and self.assertEqual(
err.value.exitCode,
COULD_NOT_STOP,
)
)
)
return stopping
class _WaitForEnd(ProcessProtocol):
def __init__(self, ended):

View File

@ -41,9 +41,6 @@ from ._twisted_9607 import (
from ..util.eliotutil import (
inline_callbacks,
)
from ..scripts.tahoe_stop import (
COULD_NOT_STOP,
)
timeout = 240
@ -614,18 +611,7 @@ class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
tahoe = CLINodeAPI(reactor, FilePath(c1))
# Set this up right now so we don't forget later.
self.addCleanup(
lambda: stop_and_wait(tahoe).addErrback(
# Let it fail because the process has already exited.
lambda err: (
err.trap(ProcessTerminated)
and self.assertEqual(
err.value.exitCode,
COULD_NOT_STOP,
)
)
)
)
self.addCleanup(tahoe.cleanup)
out, err, rc_or_sig = yield self.run_bintahoe([
"--quiet", "create-node", "--basedir", c1,