Changeset 817355d in trunk
- Timestamp:
- 2020-07-27T17:06:41Z (5 years ago)
- Branches:
- master
- Children:
- 361e758
- Parents:
- f9bda5b
- Location:
- src/allmydata
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/test/test_iputil.py ¶
rf9bda5b r817355d 14 14 from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min # noqa: F401 15 15 16 import re, errno, subprocess, os 16 import re, errno, subprocess, os, socket 17 17 18 18 from twisted.trial import unittest 19 20 from foolscap.api import Tub 19 21 20 22 from allmydata.util import iputil … … 184 186 self.patch(iputil, 'platform', "cygwin") 185 187 return self._test_list_async_mock(None, None, CYGWIN_TEST_ADDRESSES) 188 189 190 class ListenOnUsed(unittest.TestCase): 191 """Tests for listenOnUnused.""" 192 193 def create_tub(self, basedir): 194 os.makedirs(basedir) 195 tubfile = os.path.join(basedir, "tub.pem") 196 tub = Tub(certFile=tubfile) 197 tub.setOption("expose-remote-exception-types", False) 198 tub.startService() 199 self.addCleanup(tub.stopService) 200 return tub 201 202 def test_random_port(self): 203 """A random port is selected if none is given.""" 204 tub = self.create_tub("utils/ListenOnUsed/test_randomport") 205 self.assertEqual(len(tub.getListeners()), 0) 206 portnum = iputil.listenOnUnused(tub) 207 # We can connect to this port: 208 s = socket.socket() 209 s.connect(("127.0.0.1", portnum)) 210 s.close() 211 self.assertEqual(len(tub.getListeners()), 1) 212 213 # Listen on another port: 214 tub2 = self.create_tub("utils/ListenOnUsed/test_randomport_2") 215 portnum2 = iputil.listenOnUnused(tub2) 216 self.assertNotEqual(portnum, portnum2) -
TabularUnified src/allmydata/util/iputil.py ¶
rf9bda5b r817355d 380 380 "get_local_addresses_async", 381 381 "get_local_ip_for", 382 "listenOnUnused", 382 383 ]
Note: See TracChangeset
for help on using the changeset viewer.