[devtool] randomise available port search in http test

This lower the chance of parallel test to race for the same port.

authorPierre-Yves David <pierre-yves.david@logilab.fr>
changesete81bc7300a8b
branchdefault
phasedraft
hiddenyes
parent revision#59a29405688c [ext/rest] add directive bookmark to rest (closes #2545595)
child revision<not specified>
files modified by this revision
devtools/httptest.py
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1365090751 -7200
# Thu Apr 04 17:52:31 2013 +0200
# Node ID e81bc7300a8b172d359aa940a21ab074619d526e
# Parent 59a29405688c4f71fe5ecf19da7d5ab9ed672052
[devtool] randomise available port search in http test

This lower the chance of parallel test to race for the same port.

diff --git a/devtools/httptest.py b/devtools/httptest.py
@@ -18,10 +18,11 @@
1  """this module contains base classes and utilities for integration with running
2  http server
3  """
4  __docformat__ = "restructuredtext en"
5 
6 +import random
7  import threading
8  import socket
9  import httplib
10  from urlparse import urlparse
11 
@@ -44,10 +45,12 @@
12      :param ports_range: range of ports to test
13      :rtype: int
14 
15      .. see:: :func:`test.test_support.bind_port`
16      """
17 +    ports_scan = list(ports_scan)
18 +    random.shuffle(ports_scan)  # lower the chance of race condition
19      for port in ports_scan:
20          try:
21              s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
22              sock = s.connect(("localhost", port))
23          except socket.error as err: