Message65077
To be honest, I wasn't really happy either with having to return HOST,
it's somewhat redundant given that all these tests should be binding
against localhost. What about something like this for bind_port():
def bind_port(sock, host=''):
"""Bind the socket to a free port and return the port number.
Relies on ephemeral ports in order to ensure we are using an
unbound port. This is important as many tests may be running
simultaneously, especially in a buildbot environment."""
# Use a temporary socket object to ensure we're not
# affected by any socket options that have already
# been set on the 'sock' object we're passed.
tempsock = socket.socket(sock.family, sock.type)
tempsock.bind((host, 0))
port = tempsock.getsockname()[1]
tempsock.close()
del tempsock
sock.bind((host, port))
return port
The tests would then look something like:
HOST = 'localhost'
PORT = None
class Foo(TestCase):
def setUp(self):
sock = socket.socket()
global PORT
PORT = test_support.bind_port(sock, HOST)
So, the return value is the port bound to, no change there, but we're
abolishing preferred_port as an optional argument, which is important,
IMO, as none of these tests should be stipulating which port they want
to listen on. That's actually the root of this entire problem. |
|
Date |
User |
Action |
Args |
2008-04-07 16:03:53 | trent | set | spambayes_score: 0.00670221 -> 0.0067022117 recipients:
+ trent, gvanrossum, nnorwitz |
2008-04-07 16:03:53 | trent | set | spambayes_score: 0.00670221 -> 0.00670221 messageid: <1207584232.92.0.612055147909.issue2550@psf.upfronthosting.co.za> |
2008-04-07 16:03:51 | trent | link | issue2550 messages |
2008-04-07 16:03:50 | trent | create | |
|