homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author trent
Recipients gvanrossum, nnorwitz, trent
Date 2008年04月07日.16:03:49
SpamBayes Score 0.0067022117
Marked as misclassified No
Message-id <1207584232.92.0.612055147909.issue2550@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2008年04月07日 16:03:53trentsetspambayes_score: 0.00670221 -> 0.0067022117
recipients: + trent, gvanrossum, nnorwitz
2008年04月07日 16:03:53trentsetspambayes_score: 0.00670221 -> 0.00670221
messageid: <1207584232.92.0.612055147909.issue2550@psf.upfronthosting.co.za>
2008年04月07日 16:03:51trentlinkissue2550 messages
2008年04月07日 16:03:50trentcreate

AltStyle によって変換されたページ (->オリジナル) /