Skip to content

Commit

Permalink
better test
Browse files Browse the repository at this point in the history
  • Loading branch information
meejah committed Sep 4, 2017
1 parent a8abd54 commit 5163ddd
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions test/test_endpoints.py
Expand Up @@ -918,14 +918,19 @@ def test_default_socks_ports_happy(self, ep_mock):
"""

proto = object()
ports_attempted = []

class FakeSocks5(object):

def __init__(self, *args, **kw):
pass
def __init__(self, tor_ep, *args, **kw):
self.tor_port = tor_ep._port

def connect(self, *args, **kw):
return proto
ports_attempted.append(self.tor_port)
if self.tor_port != 9150:
return Failure(error.ConnectError("foo"))
else:
return proto

def _get_address(self):
return defer.succeed(None)
Expand All @@ -934,6 +939,19 @@ def _get_address(self):
endpoint = TorClientEndpoint('', 0)
p2 = yield endpoint.connect(None)
self.assertTrue(proto is p2)
self.assertEqual(
ports_attempted,
[9050, 9150]
)

# now, if we re-use the endpoint, we should again attempt the
# two ports
p3 = yield endpoint.connect(None)
self.assertTrue(proto is p3)
self.assertEqual(
ports_attempted,
[9050, 9150, 9050, 9150]
)

@patch('txtorcon.endpoints.TorSocksEndpoint')
@defer.inlineCallbacks
Expand Down

0 comments on commit 5163ddd

Please sign in to comment.