Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pymongo/asynchronous/client_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ async def callback(session, custom_arg, custom_kwarg=None):
while True:
if retry: # Implement exponential backoff on retry.
jitter = random.random() # noqa: S311
backoff = jitter * min(_BACKOFF_INITIAL * (1.5**retry), _BACKOFF_MAX)
backoff = jitter * min(_BACKOFF_INITIAL * (1.5 ** (retry - 1)), _BACKOFF_MAX)
if _would_exceed_time_limit(start_time, backoff):
assert last_error is not None
raise last_error
Expand Down
2 changes: 1 addition & 1 deletion pymongo/synchronous/client_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ def callback(session, custom_arg, custom_kwarg=None):
while True:
if retry: # Implement exponential backoff on retry.
jitter = random.random() # noqa: S311
backoff = jitter * min(_BACKOFF_INITIAL * (1.5**retry), _BACKOFF_MAX)
backoff = jitter * min(_BACKOFF_INITIAL * (1.5 ** (retry - 1)), _BACKOFF_MAX)
if _would_exceed_time_limit(start_time, backoff):
assert last_error is not None
raise last_error
Expand Down
4 changes: 3 additions & 1 deletion test/asynchronous/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,9 @@ async def callback(session):
async with self.client.start_session() as s:
await s.with_transaction(callback)
end = time.monotonic()
self.assertLess(abs(end - start - (no_backoff_time + 2.2)), 1) # sum of 13 backoffs is 2.2
self.assertLess(
abs(end - start - (no_backoff_time + 1.8)), 0.5
) # sum of 13 backoffs is 1.8

random.random = _original_random_random

Expand Down
4 changes: 3 additions & 1 deletion test/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,9 @@ def callback(session):
with self.client.start_session() as s:
s.with_transaction(callback)
end = time.monotonic()
self.assertLess(abs(end - start - (no_backoff_time + 2.2)), 1) # sum of 13 backoffs is 2.2
self.assertLess(
abs(end - start - (no_backoff_time + 1.8)), 0.5
) # sum of 13 backoffs is 1.8

random.random = _original_random_random

Expand Down
Loading