Skip to content

Commit bddd36d

Browse files
committed
PYTHON-5071 PyPy sometimes takes many retry attempts, not just one
1 parent 00034d3 commit bddd36d

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

test/__init__.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -940,15 +940,15 @@ def configure_fail_point(client, command_args, off=False):
940940
if off:
941941
cmd["mode"] = "off"
942942
cmd.pop("data", None)
943-
try:
944-
client.admin.command(cmd)
945-
return
946-
except pymongo.errors.ConnectionFailure:
947-
# Workaround PyPy bug described in PYTHON-5011.
948-
if not _IS_SYNC and "PyPy" in sys.version:
943+
for _ in range(10):
944+
try:
949945
client.admin.command(cmd)
950946
return
951-
raise
947+
except pymongo.errors.ConnectionFailure:
948+
# Workaround PyPy bug described in PYTHON-5011.
949+
if not _IS_SYNC and "PyPy" in sys.version:
950+
continue
951+
raise
952952

953953
@contextmanager
954954
def fail_point(self, command_args):
@@ -1270,7 +1270,14 @@ def teardown():
12701270
c = client_context.client
12711271
if c:
12721272
if not client_context.is_data_lake:
1273-
c.drop_database("pymongo-pooling-tests")
1273+
for _ in range(10):
1274+
try:
1275+
c.drop_database("pymongo-pooling-tests")
1276+
except pymongo.errors.ConnectionFailure:
1277+
# Workaround PyPy bug described in PYTHON-5011.
1278+
if not _IS_SYNC and "PyPy" in sys.version:
1279+
continue
1280+
raise
12741281
c.drop_database("pymongo_test")
12751282
c.drop_database("pymongo_test1")
12761283
c.drop_database("pymongo_test2")

test/asynchronous/__init__.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -942,15 +942,15 @@ async def configure_fail_point(client, command_args, off=False):
942942
if off:
943943
cmd["mode"] = "off"
944944
cmd.pop("data", None)
945-
try:
946-
await client.admin.command(cmd)
947-
return
948-
except pymongo.errors.ConnectionFailure:
949-
# Workaround PyPy bug described in PYTHON-5011.
950-
if not _IS_SYNC and "PyPy" in sys.version:
945+
for _ in range(10):
946+
try:
951947
await client.admin.command(cmd)
952948
return
953-
raise
949+
except pymongo.errors.ConnectionFailure:
950+
# Workaround PyPy bug described in PYTHON-5011.
951+
if not _IS_SYNC and "PyPy" in sys.version:
952+
continue
953+
raise
954954

955955
@asynccontextmanager
956956
async def fail_point(self, command_args):
@@ -1288,7 +1288,14 @@ async def async_teardown():
12881288
c = async_client_context.client
12891289
if c:
12901290
if not async_client_context.is_data_lake:
1291-
await c.drop_database("pymongo-pooling-tests")
1291+
for _ in range(10):
1292+
try:
1293+
await c.drop_database("pymongo-pooling-tests")
1294+
except pymongo.errors.ConnectionFailure:
1295+
# Workaround PyPy bug described in PYTHON-5011.
1296+
if not _IS_SYNC and "PyPy" in sys.version:
1297+
continue
1298+
raise
12921299
await c.drop_database("pymongo_test")
12931300
await c.drop_database("pymongo_test1")
12941301
await c.drop_database("pymongo_test2")

0 commit comments

Comments
 (0)