Skip to content

Commit 6333244

Browse files
committed
implement handshake prose test
1 parent f83e16b commit 6333244

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

pymongo/asynchronous/pool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ async def _hello(
269269
cmd = self.hello_cmd()
270270
performing_handshake = not self.performed_handshake
271271
awaitable = False
272+
cmd["backpressure"] = True
272273
if performing_handshake:
273274
self.performed_handshake = True
274275
cmd["client"] = self.opts.metadata

pymongo/synchronous/pool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def _hello(
269269
cmd = self.hello_cmd()
270270
performing_handshake = not self.performed_handshake
271271
awaitable = False
272+
cmd["backpressure"] = True
272273
if performing_handshake:
273274
self.performed_handshake = True
274275
cmd["client"] = self.opts.metadata

test/asynchronous/test_client_metadata.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ async def test_duplicate_driver_name_no_op(self):
227227
# add same metadata again
228228
await self.check_metadata_added(client, "Framework", None, None)
229229

230+
async def test_handshake_documents_include_backpressure(self):
231+
# Create a `MongoClient` that is configured to record all handshake documents sent to the server as a part of
232+
# connection establishment.
233+
client = await self.async_rs_or_single_client("mongodb://" + self.server.address_string)
234+
235+
# Send a `ping` command to the server and verify that the command succeeds. This ensure that a connection is
236+
# established on all topologies. Note: MockupDB only supports standalone servers.
237+
await client.admin.command("ping")
238+
239+
# Assert that for every handshake document intercepted:
240+
# the document has a field `backpressure` whose value is `true`.
241+
self.assertEqual(self.handshake_req["backpressure"], True)
242+
230243

231244
if __name__ == "__main__":
232245
unittest.main()

test/test_client_metadata.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ def test_duplicate_driver_name_no_op(self):
227227
# add same metadata again
228228
self.check_metadata_added(client, "Framework", None, None)
229229

230+
def test_handshake_documents_include_backpressure(self):
231+
# Create a `MongoClient` that is configured to record all handshake documents sent to the server as a part of
232+
# connection establishment.
233+
client = self.rs_or_single_client("mongodb://" + self.server.address_string)
234+
235+
# Send a `ping` command to the server and verify that the command succeeds. This ensure that a connection is
236+
# established on all topologies. Note: MockupDB only supports standalone servers.
237+
client.admin.command("ping")
238+
239+
# Assert that for every handshake document intercepted:
240+
# the document has a field `backpressure` whose value is `true`.
241+
self.assertEqual(self.handshake_req["backpressure"], True)
242+
230243

231244
if __name__ == "__main__":
232245
unittest.main()

0 commit comments

Comments
 (0)