Skip to content

Commit ade6624

Browse files
committed
IH review
1 parent bf616a2 commit ade6624

2 files changed

Lines changed: 28 additions & 32 deletions

File tree

test/asynchronous/test_client_backpressure.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
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+
5258
class 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}})

test/test_client_backpressure.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
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+
5258
class TestBackpressure(IntegrationTest):
5359
RUN_ON_LOAD_BALANCER = True
5460

@@ -57,14 +63,12 @@ def test_retry_overload_error_command(self):
5763
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
with self.fail_point(fail_many):
6368
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
with self.fail_point(fail_too_many):
6973
with self.assertRaises(PyMongoError) as error:
7074
self.db.command("find", "t")
@@ -77,14 +81,12 @@ def test_retry_overload_error_find(self):
7781
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
with self.fail_point(fail_many):
8386
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
with self.fail_point(fail_too_many):
8991
with self.assertRaises(PyMongoError) as error:
9092
self.db.t.find_one()
@@ -95,14 +97,12 @@ def test_retry_overload_error_find(self):
9597
@client_context.require_failCommand_appName
9698
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
with self.fail_point(fail_many):
101102
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
with self.fail_point(fail_too_many):
107107
with self.assertRaises(PyMongoError) as error:
108108
self.db.t.insert_one({"x": 1})
@@ -117,14 +117,12 @@ def test_retry_overload_error_update_many(self):
117117
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
with self.fail_point(fail_many):
123122
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
with self.fail_point(fail_too_many):
129127
with self.assertRaises(PyMongoError) as error:
130128
self.db.t.update_many({}, {"$set": {"x": 2}})

0 commit comments

Comments
 (0)