Adam Litke has uploaded a new change for review. Change subject: tests: Make getFreePort work in a multithreaded environment ......................................................................
tests: Make getFreePort work in a multithreaded environment getFreePort does not currently work reliably if multiple copies are running concurrently. Since each copy starts at the same port, the chance of choosing the same port number at the same time is great. Switch to letting the OS find an available port. This should fix the intermittent failures of jsonRpcTests and apiTests. Change-Id: I6adcdde3fd0312ec532b261107af45dbc87f34f3 Signed-off-by: Adam Litke <a...@us.ibm.com> --- M tests/jsonRpcUtils.py 1 file changed, 4 insertions(+), 19 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/28/12028/1 diff --git a/tests/jsonRpcUtils.py b/tests/jsonRpcUtils.py index 020f64a..66968e8 100644 --- a/tests/jsonRpcUtils.py +++ b/tests/jsonRpcUtils.py @@ -23,29 +23,14 @@ pass -_PORT_RANGE = xrange(49152, 65535) - - -_distributedPorts = [] - - def getFreePort(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) with closing(sock): - for port in _PORT_RANGE: - if port in _distributedPorts: - continue - - try: - sock.bind(("0.0.0.0", port)) - except: - continue - - _distributedPorts.append(port) - return port - else: + try: + sock.bind(("0.0.0.0", 0)) + except: raise Exception("Could not find a free port") - + return sock.getsockname()[1] @contextmanager def _tcpServerConstructor(messageHandler): -- To view, visit http://gerrit.ovirt.org/12028 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6adcdde3fd0312ec532b261107af45dbc87f34f3 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam Litke <a...@us.ibm.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches