def test_when_connected_already(self): tpp = TorProcessProtocol(lambda: None) # hmmmmmph, delving into internal state "because way shorter # test" tpp._connected_listeners = None d = tpp.when_connected() self.assertTrue(d.called) self.assertEqual(d.result, tpp)
def test_progress_updates(self): self.got_progress = False def confirm_progress(p, t, s): self.assertEqual(p, 10) self.assertEqual(t, 'tag') self.assertEqual(s, 'summary') self.got_progress = True process = TorProcessProtocol(None, confirm_progress) process.progress(10, 'tag', 'summary') self.assertTrue(self.got_progress)
def test_quit_process_error(self): process = TorProcessProtocol(None) process.transport = Mock() def boom(sig): self.assertEqual(sig, 'TERM') raise RuntimeError("Something bad") process.transport.signalProcess = Mock(side_effect=boom) try: yield process.quit() except RuntimeError as e: self.assertEqual("Something bad", str(e))
def test_happy_path(self, warn, ftb): self.transport = proto_helpers.StringTransport() class Connector: def __call__(self, proto, trans): proto._set_valid_events('STATUS_CLIENT') proto.makeConnection(trans) proto.post_bootstrap.callback(proto) return proto.post_bootstrap self.protocol = FakeControlProtocol([]) trans = Mock() trans.protocol = self.protocol creator = functools.partial(Connector(), self.protocol, self.transport) reactor = Mock() config = Mock() fake_tor = Mock() fake_tor.process = TorProcessProtocol(creator) with patch('txtorcon.controller.launch', return_value=fake_tor) as launch: directlyProvides(reactor, IReactorCore) tpp = yield launch_tor( config, reactor, connection_creator=creator ) self.assertEqual(1, len(launch.mock_calls)) self.assertTrue( isinstance(tpp, TorProcessProtocol) ) self.assertIs(tpp, fake_tor.process) calls = warn.mock_calls self.assertEqual(1, len(calls)) self.assertEqual(calls[0][1][1], DeprecationWarning)
def test_quit_process(self): process = TorProcessProtocol(None) process.transport = Mock() d = process.quit() self.assertFalse(d.called) process.processExited(Failure(error.ProcessTerminated(exitCode=15))) self.assertTrue(d.called) process.processEnded(Failure(error.ProcessDone(None))) self.assertTrue(d.called) errs = self.flushLoggedErrors() self.assertEqual(1, len(errs)) self.assertTrue("Tor exited with error-code" in str(errs[0]))
def test_quit_process_already(self): process = TorProcessProtocol(None) process.transport = Mock() def boom(sig): self.assertEqual(sig, 'TERM') raise error.ProcessExitedAlready() process.transport.signalProcess = Mock(side_effect=boom) d = process.quit() process.processEnded(Failure(error.ProcessDone(None))) self.assertTrue(d.called) errs = self.flushLoggedErrors() self.assertEqual(1, len(errs)) self.assertTrue("Tor exited with error-code" in str(errs[0]))
def XXXtest_tor_launch_success_then_shutdown(self): """ There was an error where we double-callbacked a deferred, i.e. success and then shutdown. This repeats it. """ process = TorProcessProtocol(None) process.status_client( 'STATUS_CLIENT BOOTSTRAP PROGRESS=100 TAG=foo SUMMARY=cabbage') # XXX why this assert? self.assertEqual(None, process._connected_cb) class Value(object): exitCode = 123 class Status(object): value = Value() process.processEnded(Status()) self.assertEquals(len(self.flushLoggedErrors(RuntimeError)), 1)
def XXXtest_status_updates(self): process = TorProcessProtocol(None) process.status_client("NOTICE CONSENSUS_ARRIVED")
def test_ctor_timeout_no_ireactortime(self): with self.assertRaises(RuntimeError) as ctx: TorProcessProtocol(lambda: None, timeout=42) self.assertTrue("Must supply an IReactorTime" in str(ctx.exception))