[pypy-svn] pypy default: Don't use always port 50007 (risk of collision when running twice).

arigo commits-noreply at bitbucket.org
Mon Feb 14 11:58:10 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r41894:e159fe203839
Date: 2011-02-14 11:57 +0100
http://bitbucket.org/pypy/pypy/changeset/e159fe203839/

Log:	Don't use always port 50007 (risk of collision when running twice).
	Instead, use a random port number.

diff --git a/pypy/module/_socket/test/test_sock_app.py b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -1,10 +1,12 @@
 from pypy.conftest import gettestobjspace
-import sys
+import sys, random
 import py
 from pypy.tool.udir import udir
 from pypy.rlib import rsocket
 from pypy.rpython.lltypesystem import lltype, rffi
 
+PORT_NUMBER = random.randrange(40000, 60000)
+
 def setup_module(mod):
     mod.space = gettestobjspace(usemodules=['_socket', 'array'])
     global socket
@@ -297,6 +299,7 @@
     def setup_class(cls):
         cls.space = space
         cls.w_udir = space.wrap(str(udir))
+        cls.w_PORT = space.wrap(PORT_NUMBER)
 
     def test_ntoa_exception(self):
         import _socket
@@ -498,7 +501,7 @@
             skip('No dup() on this platform')
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-        s.bind(('localhost', 50007))
+        s.bind(('localhost', self.PORT))
         s2 = s.dup()
         assert s.fileno() != s2.fileno()
         assert s.getsockname() == s2.getsockname()
@@ -554,7 +557,7 @@
     def setup_class(cls):
         cls.space = space
 
-    PORT = 50007
+    PORT = PORT_NUMBER
     HOST = 'localhost'
         
     def setup_method(self, method):


More information about the Pypy-commit mailing list