@@ -208,9 +208,6 @@ class SlapdObject(object):
208
208
BIN_PATH = os .environ .get ('BIN' , os .environ .get ('PATH' , os .defpath ))
209
209
SBIN_PATH = os .environ .get ('SBIN' , _add_sbin (BIN_PATH ))
210
210
211
- # time in secs to wait before trying to access slapd via LDAP (again)
212
- _start_sleep = 1.5
213
-
214
211
# create loggers once, multiple calls mess up refleak tests
215
212
_log = combined_logger ('python-ldap-test' )
216
213
@@ -418,20 +415,22 @@ def _start_slapd(self):
418
415
self ._log .info ('starting slapd: %r' , ' ' .join (slapd_args ))
419
416
self ._proc = subprocess .Popen (slapd_args )
420
417
# Waits until the LDAP server socket is open, or slapd crashed
418
+ deadline = time .monotonic () + 10
421
419
# no cover to avoid spurious coverage changes, see
422
420
# https://github.com/python-ldap/python-ldap/issues/127
423
- for _ in range ( 10 ) : # pragma: no cover
421
+ while True : # pragma: no cover
424
422
if self ._proc .poll () is not None :
425
423
self ._stopped ()
426
424
raise RuntimeError ("slapd exited before opening port" )
427
- time .sleep (self ._start_sleep )
428
425
try :
429
426
self ._log .debug (
430
427
"slapd connection check to %s" , self .default_ldap_uri
431
428
)
432
429
self .ldapwhoami ()
433
430
except RuntimeError :
434
- pass
431
+ if time .monotonic () >= deadline :
432
+ break
433
+ time .sleep (0.2 )
435
434
else :
436
435
return
437
436
raise RuntimeError ("slapd did not start properly" )
0 commit comments