Skip to content

PYTHON-5409 Make test_implicit_sessions_checkout less flaky #2366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025
Merged
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
13 changes: 7 additions & 6 deletions test/asynchronous/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,11 @@ async def test_implicit_sessions_checkout(self):
# successful connection checkout" test from Driver Sessions Spec.
succeeded = False
lsid_set = set()
failures = 0
for _ in range(5):
listener = OvertCommandListener()
client = await self.async_rs_or_single_client(event_listeners=[listener], maxPoolSize=1)
listener = OvertCommandListener()
client = await self.async_rs_or_single_client(event_listeners=[listener], maxPoolSize=1)
# Retry up to 10 times because there is a known race that can cause multiple
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

condition

# sessions to be used: connection check in happens before session check in
for _ in range(10):
cursor = client.db.test.find({})
ops: List[Tuple[Callable, List[Any]]] = [
(client.db.test.find_one, [{"_id": 1}]),
Expand Down Expand Up @@ -240,9 +241,9 @@ async def target(op, *args):
if i.command.get("lsid"):
lsid_set.add(i.command.get("lsid")["id"])
if len(lsid_set) == 1:
# Break on first success.
succeeded = True
else:
failures += 1
break
self.assertTrue(succeeded, lsid_set)

async def test_pool_lifo(self):
Expand Down
13 changes: 7 additions & 6 deletions test/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,11 @@ def test_implicit_sessions_checkout(self):
# successful connection checkout" test from Driver Sessions Spec.
succeeded = False
lsid_set = set()
failures = 0
for _ in range(5):
listener = OvertCommandListener()
client = self.rs_or_single_client(event_listeners=[listener], maxPoolSize=1)
listener = OvertCommandListener()
client = self.rs_or_single_client(event_listeners=[listener], maxPoolSize=1)
# Retry up to 10 times because there is a known race that can cause multiple
# sessions to be used: connection check in happens before session check in
for _ in range(10):
cursor = client.db.test.find({})
ops: List[Tuple[Callable, List[Any]]] = [
(client.db.test.find_one, [{"_id": 1}]),
Expand Down Expand Up @@ -240,9 +241,9 @@ def target(op, *args):
if i.command.get("lsid"):
lsid_set.add(i.command.get("lsid")["id"])
if len(lsid_set) == 1:
# Break on first success.
succeeded = True
else:
failures += 1
break
self.assertTrue(succeeded, lsid_set)

def test_pool_lifo(self):
Expand Down
Loading