Skip to content

Commit 00034d3

Browse files
committed
PYTHON-5071 Fix configureFailPoint retry
1 parent 7584831 commit 00034d3

File tree

4 files changed

+14
-20
lines changed

4 files changed

+14
-20
lines changed

test/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -934,9 +934,12 @@ def assertEqualReply(self, expected, actual, msg=None):
934934
self.assertEqual(sanitize_reply(expected), sanitize_reply(actual), msg)
935935

936936
@staticmethod
937-
def configure_fail_point(client, command_args):
937+
def configure_fail_point(client, command_args, off=False):
938938
cmd = {"configureFailPoint": "failCommand"}
939939
cmd.update(command_args)
940+
if off:
941+
cmd["mode"] = "off"
942+
cmd.pop("data", None)
940943
try:
941944
client.admin.command(cmd)
942945
return
@@ -949,13 +952,11 @@ def configure_fail_point(client, command_args):
949952

950953
@contextmanager
951954
def fail_point(self, command_args):
952-
name = command_args.get("configureFailPoint", "failCommand")
953955
self.configure_fail_point(client_context.client, command_args)
954956
try:
955957
yield
956958
finally:
957-
cmd_off = {"configureFailPoint": name, "mode": "off"}
958-
self.configure_fail_point(client_context.client, cmd_off)
959+
self.configure_fail_point(client_context.client, command_args, off=True)
959960

960961
@contextmanager
961962
def fork(

test/asynchronous/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -936,9 +936,12 @@ def assertEqualReply(self, expected, actual, msg=None):
936936
self.assertEqual(sanitize_reply(expected), sanitize_reply(actual), msg)
937937

938938
@staticmethod
939-
async def configure_fail_point(client, command_args):
939+
async def configure_fail_point(client, command_args, off=False):
940940
cmd = {"configureFailPoint": "failCommand"}
941941
cmd.update(command_args)
942+
if off:
943+
cmd["mode"] = "off"
944+
cmd.pop("data", None)
942945
try:
943946
await client.admin.command(cmd)
944947
return
@@ -951,13 +954,11 @@ async def configure_fail_point(client, command_args):
951954

952955
@asynccontextmanager
953956
async def fail_point(self, command_args):
954-
name = command_args.get("configureFailPoint", "failCommand")
955957
await self.configure_fail_point(async_client_context.client, command_args)
956958
try:
957959
yield
958960
finally:
959-
cmd_off = {"configureFailPoint": name, "mode": "off"}
960-
await self.configure_fail_point(async_client_context.client, cmd_off)
961+
await self.configure_fail_point(async_client_context.client, command_args, off=True)
961962

962963
@contextmanager
963964
def fork(

test/asynchronous/unified_format.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,12 +1008,8 @@ async def __set_fail_point(self, client, command_args):
10081008
if not async_client_context.test_commands_enabled:
10091009
self.skipTest("Test commands must be enabled")
10101010

1011-
cmd_on = SON([("configureFailPoint", "failCommand")])
1012-
cmd_on.update(command_args)
1013-
await client.admin.command(cmd_on)
1014-
self.addAsyncCleanup(
1015-
client.admin.command, "configureFailPoint", cmd_on["configureFailPoint"], mode="off"
1016-
)
1011+
await self.configure_fail_point(client, command_args)
1012+
self.addAsyncCleanup(self.configure_fail_point, client, command_args, off=True)
10171013

10181014
async def _testOperation_failPoint(self, spec):
10191015
await self.__set_fail_point(

test/unified_format.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -999,12 +999,8 @@ def __set_fail_point(self, client, command_args):
999999
if not client_context.test_commands_enabled:
10001000
self.skipTest("Test commands must be enabled")
10011001

1002-
cmd_on = SON([("configureFailPoint", "failCommand")])
1003-
cmd_on.update(command_args)
1004-
client.admin.command(cmd_on)
1005-
self.addCleanup(
1006-
client.admin.command, "configureFailPoint", cmd_on["configureFailPoint"], mode="off"
1007-
)
1002+
self.configure_fail_point(client, command_args)
1003+
self.addCleanup(self.configure_fail_point, client, command_args, off=True)
10081004

10091005
def _testOperation_failPoint(self, spec):
10101006
self.__set_fail_point(

0 commit comments

Comments
 (0)