4949}
5050
5151
52+ def get_mock_overload_error (times : int ):
53+ error = mock_overload_error .copy ()
54+ error ["mode" ] = {"times" : times }
55+ return error
56+
57+
5258class TestBackpressure (AsyncIntegrationTest ):
5359 RUN_ON_LOAD_BALANCER = True
5460
@@ -57,14 +63,12 @@ async def test_retry_overload_error_command(self):
5763 await self .db .t .insert_one ({"x" : 1 })
5864
5965 # Ensure command is retried on overload error.
60- fail_many = mock_overload_error .copy ()
61- fail_many ["mode" ] = {"times" : MAX_ADAPTIVE_RETRIES }
66+ fail_many = get_mock_overload_error (MAX_ADAPTIVE_RETRIES )
6267 async with self .fail_point (fail_many ):
6368 await self .db .command ("find" , "t" )
6469
6570 # Ensure command stops retrying after MAX_ADAPTIVE_RETRIES.
66- fail_too_many = mock_overload_error .copy ()
67- fail_too_many ["mode" ] = {"times" : MAX_ADAPTIVE_RETRIES + 1 }
71+ fail_too_many = get_mock_overload_error (MAX_ADAPTIVE_RETRIES + 1 )
6872 async with self .fail_point (fail_too_many ):
6973 with self .assertRaises (PyMongoError ) as error :
7074 await self .db .command ("find" , "t" )
@@ -77,14 +81,12 @@ async def test_retry_overload_error_find(self):
7781 await self .db .t .insert_one ({"x" : 1 })
7882
7983 # Ensure command is retried on overload error.
80- fail_many = mock_overload_error .copy ()
81- fail_many ["mode" ] = {"times" : MAX_ADAPTIVE_RETRIES }
84+ fail_many = get_mock_overload_error (MAX_ADAPTIVE_RETRIES )
8285 async with self .fail_point (fail_many ):
8386 await self .db .t .find_one ()
8487
8588 # Ensure command stops retrying after MAX_ADAPTIVE_RETRIES.
86- fail_too_many = mock_overload_error .copy ()
87- fail_too_many ["mode" ] = {"times" : MAX_ADAPTIVE_RETRIES + 1 }
89+ fail_too_many = get_mock_overload_error (MAX_ADAPTIVE_RETRIES + 1 )
8890 async with self .fail_point (fail_too_many ):
8991 with self .assertRaises (PyMongoError ) as error :
9092 await self .db .t .find_one ()
@@ -95,14 +97,12 @@ async def test_retry_overload_error_find(self):
9597 @async_client_context .require_failCommand_appName
9698 async def test_retry_overload_error_insert_one (self ):
9799 # Ensure command is retried on overload error.
98- fail_many = mock_overload_error .copy ()
99- fail_many ["mode" ] = {"times" : MAX_ADAPTIVE_RETRIES }
100+ fail_many = get_mock_overload_error (MAX_ADAPTIVE_RETRIES )
100101 async with self .fail_point (fail_many ):
101102 await self .db .t .insert_one ({"x" : 1 })
102103
103104 # Ensure command stops retrying after MAX_ADAPTIVE_RETRIES.
104- fail_too_many = mock_overload_error .copy ()
105- fail_too_many ["mode" ] = {"times" : MAX_ADAPTIVE_RETRIES + 1 }
105+ fail_too_many = get_mock_overload_error (MAX_ADAPTIVE_RETRIES + 1 )
106106 async with self .fail_point (fail_too_many ):
107107 with self .assertRaises (PyMongoError ) as error :
108108 await self .db .t .insert_one ({"x" : 1 })
@@ -117,14 +117,12 @@ async def test_retry_overload_error_update_many(self):
117117 await self .db .t .insert_one ({"x" : 1 })
118118
119119 # Ensure command is retried on overload error.
120- fail_many = mock_overload_error .copy ()
121- fail_many ["mode" ] = {"times" : MAX_ADAPTIVE_RETRIES }
120+ fail_many = get_mock_overload_error (MAX_ADAPTIVE_RETRIES )
122121 async with self .fail_point (fail_many ):
123122 await self .db .t .update_many ({}, {"$set" : {"x" : 2 }})
124123
125124 # Ensure command stops retrying after MAX_ADAPTIVE_RETRIES.
126- fail_too_many = mock_overload_error .copy ()
127- fail_too_many ["mode" ] = {"times" : MAX_ADAPTIVE_RETRIES + 1 }
125+ fail_too_many = get_mock_overload_error (MAX_ADAPTIVE_RETRIES + 1 )
128126 async with self .fail_point (fail_too_many ):
129127 with self .assertRaises (PyMongoError ) as error :
130128 await self .db .t .update_many ({}, {"$set" : {"x" : 2 }})
0 commit comments