# HG changeset patch # User Sylvain Thénault # Date 1297439143 -3600 # Node ID 18343456ee497271d53969e180bf1661ed9eb1d9 # Parent dda970c8a3153911198ec2b54f2d9e4990951194 [ldap test] use get_available_port from cw.devtools.httptest diff -r dda970c8a315 -r 18343456ee49 server/test/unittest_ldapuser.py --- a/server/test/unittest_ldapuser.py Fri Feb 11 13:38:40 2011 +0100 +++ b/server/test/unittest_ldapuser.py Fri Feb 11 16:45:43 2011 +0100 @@ -27,6 +27,7 @@ from logilab.common.testlib import TestCase, unittest_main, mock_object from cubicweb.devtools.testlib import CubicWebTC from cubicweb.devtools.repotest import RQLGeneratorTC +from cubicweb.devtools.httptest import get_available_port from cubicweb.server.sources.ldapuser import * @@ -102,19 +103,7 @@ #ldapuri = 'ldapi://' + join(basedir, "ldapi").replace('/', '%2f') - for port in range(9000, 9100): - try: - socket().bind(('localhost', port)) - except socketerror, e: - if e.errno == 98: # Address already in use - pass - else: - raise - else: - break - else: - raise Exception("Can't find a free TCP port on localhost") - + port = get_available_port(xrange(9000, 9100)) host = 'localhost:%s' % port ldapuri = 'ldap://%s' % host cmdline = ["/usr/sbin/slapd", "-f", slapdconf, "-h", ldapuri, "-d", "0"] @@ -132,7 +121,11 @@ global slapd_process if slapd_process.returncode is None: print "terminating slapd" - slapd_process.terminate() + if hasattr(slapd_process, 'terminate'): + slapd_process.terminate() + else: + import os, signal + os.kill(slapd_process.pid, signal.SIGTERM) slapd_process.wait() print "DONE"