[devtool] randomise available ports search in http test stable
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Wed, 03 Jul 2013 14:52:10 +0200
branchstable
changeset 9136 eef0388e8fea
parent 9135 d42540bacff4
child 9137 c791d8fddc15
[devtool] randomise available ports search in http test This lowers the chance of parallel tests to race for the same port.
devtools/httptest.py
--- a/devtools/httptest.py	Wed Jul 03 14:48:34 2013 +0200
+++ b/devtools/httptest.py	Wed Jul 03 14:52:10 2013 +0200
@@ -20,6 +20,7 @@
 """
 __docformat__ = "restructuredtext en"
 
+import random
 import threading
 import socket
 import httplib
@@ -46,6 +47,8 @@
 
     .. see:: :func:`test.test_support.bind_port`
     """
+    ports_scan = list(ports_scan)
+    random.shuffle(ports_scan)  # lower the chance of race condition
     for port in ports_scan:
         try:
             s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)