Skip to content

Commit 4fc9038

Browse files
authored
slapdtest: Rework waiting for SlapdObject startup
This gives a chance to SlapdObject to start faster. Notably it does not start by sleeping 1.5s anymore. python-ldap#390
1 parent 3ea12d6 commit 4fc9038

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Lib/slapdtest/_slapdtest.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ class SlapdObject(object):
208208
BIN_PATH = os.environ.get('BIN', os.environ.get('PATH', os.defpath))
209209
SBIN_PATH = os.environ.get('SBIN', _add_sbin(BIN_PATH))
210210

211-
# time in secs to wait before trying to access slapd via LDAP (again)
212-
_start_sleep = 1.5
213-
214211
# create loggers once, multiple calls mess up refleak tests
215212
_log = combined_logger('python-ldap-test')
216213

@@ -418,20 +415,22 @@ def _start_slapd(self):
418415
self._log.info('starting slapd: %r', ' '.join(slapd_args))
419416
self._proc = subprocess.Popen(slapd_args)
420417
# Waits until the LDAP server socket is open, or slapd crashed
418+
deadline = time.monotonic() + 10
421419
# no cover to avoid spurious coverage changes, see
422420
# https://github.com/python-ldap/python-ldap/issues/127
423-
for _ in range(10): # pragma: no cover
421+
while True: # pragma: no cover
424422
if self._proc.poll() is not None:
425423
self._stopped()
426424
raise RuntimeError("slapd exited before opening port")
427-
time.sleep(self._start_sleep)
428425
try:
429426
self._log.debug(
430427
"slapd connection check to %s", self.default_ldap_uri
431428
)
432429
self.ldapwhoami()
433430
except RuntimeError:
434-
pass
431+
if time.monotonic() >= deadline:
432+
break
433+
time.sleep(0.2)
435434
else:
436435
return
437436
raise RuntimeError("slapd did not start properly")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy