(self)
| 1505 | # XXX The following don't test module-level functionality... |
| 1506 | |
| 1507 | def testSockName(self): |
| 1508 | # Testing getsockname() |
| 1509 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 1510 | self.addCleanup(sock.close) |
| 1511 | |
| 1512 | # Since find_unused_port() is inherently subject to race conditions, we |
| 1513 | # call it a couple times if necessary. |
| 1514 | for i in itertools.count(): |
| 1515 | port = socket_helper.find_unused_port() |
| 1516 | try: |
| 1517 | sock.bind(("0.0.0.0", port)) |
| 1518 | except OSError as e: |
| 1519 | if e.errno != errno.EADDRINUSE or i == 5: |
| 1520 | raise |
| 1521 | else: |
| 1522 | break |
| 1523 | |
| 1524 | name = sock.getsockname() |
| 1525 | # XXX(nnorwitz): http://tinyurl.com/os5jz seems to indicate |
| 1526 | # it reasonable to get the host's addr in addition to 0.0.0.0. |
| 1527 | # At least for eCos. This is required for the S/390 to pass. |
| 1528 | try: |
| 1529 | my_ip_addr = socket.gethostbyname(socket.gethostname()) |
| 1530 | except OSError: |
| 1531 | # Probably name lookup wasn't set up right; skip this test |
| 1532 | self.skipTest('name lookup failure') |
| 1533 | self.assertIn(name[0], ("0.0.0.0", my_ip_addr), '%s invalid' % name[0]) |
| 1534 | self.assertEqual(name[1], port) |
| 1535 | |
| 1536 | def testGetSockOpt(self): |
| 1537 | # Testing getsockopt() |
nothing calls this directly
no test coverage detected