def setUp(self): super(TestTahoeMonitor, self).setUp() self.root = create_fake_tahoe_root() self.http_client = create_tahoe_treq_client(self.root) self.tahoe_client = create_tahoe_client( DecodedURL.from_text(u"http://example.com"), self.http_client, ) self.node = self.useFixture(NodeDirectory(FilePath(self.mktemp()))) # when the "service" is run it wants to check shares-happy from Tahoe with self.node.tahoe_cfg.open("w") as f: f.write(b"[client]\nshares.happy = 1\n") self.basedir = FilePath(self.mktemp()) self.config = create_global_configuration( self.basedir, u"tcp:0", self.node.path, u"tcp:localhost:0", ) self.reactor = MemoryReactorClock() self.service = MagicFolderService( self.reactor, self.config, WebSocketStatusService(self.reactor, self.config), self.tahoe_client, )
def test_passes_reactor(self): """ `default_reactor()` returns any reactor passed. """ reactor = MemoryReactorClock() self.assertIs(default_reactor(reactor), reactor)
def mkTreq(self): """ Construct a :class:`treq.testing.StubTreq` which wraps a :class:`yarrharr.application.Root` resource. """ reactor = MemoryReactorClock() # unused threadpool = ThreadPool(minthreads=0) # unused self.addCleanup(threadpool.stop) return StubTreq(Root(reactor, threadpool))
def __init__(self, rootResource): """ :param rootResource: The Twisted `IResource` at the root of the resource tree. """ self._memoryReactor = MemoryReactorClock() self._realAgent = Agent.usingEndpointFactory( reactor=self._memoryReactor, endpointFactory=_EndpointFactory(self._memoryReactor)) self._rootResource = rootResource self._pumps = set()
def test_tahoe_stops_streamedlogs(monkeypatch, tahoe_factory): monkeypatch.setattr( "gridsync.tahoe.Tahoe.command", lambda self, args, callback_trigger=None: 9999, ) tahoe = tahoe_factory(MemoryReactorClock()) tahoe.monitor = Mock() tahoe.config_set("client", "shares.needed", "3") tahoe.config_set("client", "shares.happy", "7") tahoe.config_set("client", "shares.total", "10") yield tahoe.start() write_pidfile(tahoe.nodedir) yield tahoe.stop() assert not tahoe.streamedlogs.running
def test_tahoe_starts_streamedlogs(monkeypatch, tahoe_factory): monkeypatch.setattr( "gridsync.tahoe.Tahoe.command", lambda self, args, callback_trigger=None: 9999, ) reactor = MemoryReactorClock() tahoe = tahoe_factory(reactor) tahoe.monitor = Mock() tahoe.config_set("client", "shares.needed", "3") tahoe.config_set("client", "shares.happy", "7") tahoe.config_set("client", "shares.total", "10") yield tahoe.start() assert tahoe.streamedlogs.running (host, port, _, _, _) = reactor.tcpClients.pop(0) assert (host, port) == ("example.invalid", 12345)
def connectableEndpoint(debug=False): """ Create an endpoint that can be fired on demand. @param debug: A flag; whether to dump output from the established connection to stdout. @type debug: L{bool} @return: A client endpoint, and an object that will cause one of the L{Deferred}s returned by that client endpoint. @rtype: 2-L{tuple} of (L{IStreamClientEndpoint}, L{ConnectionCompleter}) """ reactor = MemoryReactorClock() clientEndpoint = TCP4ClientEndpoint(reactor, "0.0.0.0", 4321) serverEndpoint = TCP4ServerEndpoint(reactor, 4321) serverEndpoint.listen(Factory.forProtocol(Protocol)) return clientEndpoint, ConnectionCompleter(reactor)
def setUp(self): set_global_pool(None) self.reactor = MemoryReactorClock()