Skip to content

Commit 077ba59

Browse files
committed
adaptive retries
1 parent e2785c2 commit 077ba59

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

docker/mongodb-kubernetes-tests/kubetester/mongotester.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,15 @@ def assert_scram_sha_authentication(
195195
except OperationFailure as e:
196196
if i == 0:
197197
fail(f"unable to authenticate after {attempts} attempts with error: {e}")
198-
time.sleep(5)
198+
199+
# Use adaptive retry delays for better password propagation handling
200+
remaining_attempts = i
201+
if remaining_attempts >= attempts * 0.7: # First ~30% of attempts
202+
delay = 10 # Longer delay for initial propagation
203+
else:
204+
delay = 5 # Standard delay for normal retries
205+
206+
time.sleep(delay)
199207

200208
def assert_scram_sha_authentication_fails(
201209
self,
@@ -239,7 +247,7 @@ def _authenticate_with_scram(
239247
# authentication doesn't actually happen until we interact with a database
240248
self.client["admin"]["myCol"].insert_one({})
241249

242-
def assert_x509_authentication(self, cert_file_name: str, attempts: int = 20, **kwargs):
250+
def assert_x509_authentication(self, cert_file_name: str, attempts: int = 30, **kwargs):
243251
assert attempts > 0
244252

245253
options = self._merge_options(
@@ -258,7 +266,15 @@ def assert_x509_authentication(self, cert_file_name: str, attempts: int = 20, **
258266
except OperationFailure:
259267
if attempts == 0:
260268
fail(f"unable to authenticate after {total_attempts} attempts")
261-
time.sleep(5)
269+
270+
# Use adaptive retry delays for better credential propagation handling
271+
remaining_attempts = attempts
272+
if remaining_attempts >= total_attempts * 0.7: # First ~30% of attempts
273+
delay = 10 # Longer delay for initial propagation
274+
else:
275+
delay = 5 # Standard delay for normal retries
276+
277+
time.sleep(delay)
262278

263279
def assert_ldap_authentication(
264280
self,
@@ -290,7 +306,15 @@ def assert_ldap_authentication(
290306
except OperationFailure:
291307
if attempts <= 0:
292308
fail(f"unable to authenticate after {total_attempts} attempts")
293-
time.sleep(5)
309+
310+
# Use adaptive retry delays for better credential propagation handling
311+
remaining_attempts = attempts
312+
if remaining_attempts >= total_attempts * 0.7: # First ~30% of attempts
313+
delay = 10 # Longer delay for initial propagation
314+
else:
315+
delay = 5 # Standard delay for normal retries
316+
317+
time.sleep(delay)
294318

295319
def assert_oidc_authentication(
296320
self,
@@ -317,7 +341,15 @@ def assert_oidc_authentication(
317341
except OperationFailure as e:
318342
if attempts == 0:
319343
raise RuntimeError(f"Unable to authenticate after {total_attempts} attempts: {e}")
320-
time.sleep(5)
344+
345+
# Use adaptive retry delays for better credential propagation handling
346+
remaining_attempts = attempts
347+
if remaining_attempts >= total_attempts * 0.7: # First ~30% of attempts
348+
delay = 10 # Longer delay for initial propagation
349+
else:
350+
delay = 5 # Standard delay for normal retries
351+
352+
time.sleep(delay)
321353

322354
def assert_oidc_authentication_fails(self, db: str = "admin", collection: str = "myCol", attempts: int = 10):
323355
assert attempts > 0

0 commit comments

Comments
 (0)