@@ -49,17 +49,15 @@ This test applies to drivers with session pools.
4949
5050### 3. ` $clusterTime ` in commands
5151
52- - Turn ` heartbeatFrequencyMS ` up to a very large number.
5352- Register a command-started and a command-succeeded APM listener. If the driver has no APM support, inspect
54- commands/replies in another idiomatic way, such as monkey-patching or a mock server.
53+ commands/replies in another idiomatic way, such as monkey-patching or a mock server.
5554- Send a ` ping ` command to the server with the generic ` runCommand ` method.
5655- Assert that the command passed to the command-started listener includes ` $clusterTime ` if and only if ` maxWireVersion `
57- > = 6.
56+ > = 6.
5857- Record the ` $clusterTime ` , if any, in the reply passed to the command-succeeded APM listener.
5958- Send another ` ping ` command.
6059- Assert that ` $clusterTime ` in the command passed to the command-started listener, if any, equals the ` $clusterTime ` in
61- the previous server reply. (Turning ` heartbeatFrequencyMS ` up prevents an intervening heartbeat from advancing the
62- ` $clusterTime ` between these final two steps.)
60+ the previous server reply.
6361
6462Repeat the above for:
6563
@@ -70,7 +68,7 @@ Repeat the above for:
7068### 4. Explicit and implicit session arguments
7169
7270- Register a command-started APM listener. If the driver has no APM support, inspect commands in another idiomatic way,
73- such as monkey-patching or a mock server.
71+ such as monkey-patching or a mock server.
7472- Create ` client1 `
7573- Get ` database ` from ` client1 `
7674- Get ` collection ` from ` database `
@@ -120,9 +118,9 @@ Skip this test if your driver does not allow simultaneous authentication with mu
120118- Insert two documents into a collection
121119- Execute a find operation on the collection and iterate past the first document
122120- Assert that the implicit session is returned to the pool. This can be done in several ways:
123- - Track in-use count in the server session pool and assert that the count has dropped to zero
124- - Track the lsid used for the find operation (e.g. with APM) and then do another operation and assert that the same
125- lsid is used as for the find operation.
121+ - Track in-use count in the server session pool and assert that the count has dropped to zero
122+ - Track the lsid used for the find operation (e.g. with APM) and then do another operation and assert that the same
123+ lsid is used as for the find operation.
126124
127125### 9. Client-side cursor that exhausts the results after a ` getMore ` immediately returns the implicit session to the pool
128126
@@ -169,32 +167,32 @@ Skip this test if your driver does not allow forking.
169167### 14. Implicit sessions only allocate their server session after a successful connection checkout
170168
171169- Create a MongoClient with the following options: ` maxPoolSize=1 ` and ` retryWrites=true ` . If testing against a sharded
172- deployment, the test runner MUST ensure that the MongoClient connects to only a single mongos host.
170+ deployment, the test runner MUST ensure that the MongoClient connects to only a single mongos host.
173171- Attach a command started listener that collects each command's lsid
174172- Initiate the following concurrent operations
175- - ` insertOne({ }), `
176- - ` deleteOne({ }), `
177- - ` updateOne({ }, { $set: { a: 1 } }), `
178- - ` bulkWrite([{ updateOne: { filter: { }, update: { $set: { a: 1 } } } }]), `
179- - ` findOneAndDelete({ }), `
180- - ` findOneAndUpdate({ }, { $set: { a: 1 } }), `
181- - ` findOneAndReplace({ }, { a: 1 }), `
182- - ` find().toArray() `
173+ - ` insertOne({ }), `
174+ - ` deleteOne({ }), `
175+ - ` updateOne({ }, { $set: { a: 1 } }), `
176+ - ` bulkWrite([{ updateOne: { filter: { }, update: { $set: { a: 1 } } } }]), `
177+ - ` findOneAndDelete({ }), `
178+ - ` findOneAndUpdate({ }, { $set: { a: 1 } }), `
179+ - ` findOneAndReplace({ }, { a: 1 }), `
180+ - ` find().toArray() `
183181- Wait for all operations to complete successfully
184182- Assert the following across at least 5 retries of the above test:
185- - Drivers MUST assert that exactly one session is used for all operations at least once across the retries of this
186- test.
187- - Note that it's possible, although rare, for >1 server session to be used because the session is not released until
188- after the connection is checked in.
189- - Drivers MUST assert that the number of allocated sessions is strictly less than the number of concurrent operations
190- in every retry of this test. In this instance it would be less than (but NOT equal to) 8.
183+ - Drivers MUST assert that exactly one session is used for all operations at least once across the retries of this
184+ test.
185+ - Note that it's possible, although rare, for >1 server session to be used because the session is not released until
186+ after the connection is checked in.
187+ - Drivers MUST assert that the number of allocated sessions is strictly less than the number of concurrent operations
188+ in every retry of this test. In this instance it would be less than (but NOT equal to) 8.
191189
192190### 15. ` lsid ` is added inside ` $query ` when using OP_QUERY
193191
194192This test only applies to drivers that have not implemented OP_MSG and still use OP_QUERY.
195193
196194- For a command to a mongos that includes a readPreference, verify that the ` lsid ` on query commands is added inside the
197- ` $query ` field, and NOT as a top-level field.
195+ ` $query ` field, and NOT as a top-level field.
198196
199197### 16. Authenticating as a second user after starting a session results in a server error
200198
@@ -238,8 +236,23 @@ and configure a `MongoClient` with default options.
238236- Attempt to send a write command to the server (e.g., ` insertOne ` ) with the explicit session passed in
239237- Assert that a client-side error is generated indicating that sessions are not supported
240238
239+ ### 20. Drivers do not gossip ` $clusterTime ` on SDAM commands.
240+
241+ - Skip this test when connected to a deployment that does not support cluster times
242+ - Create a client, C1, directly connected to a writable server and a small heartbeatFrequencyMS
243+ - ` c1 = MongoClient(directConnection=True, heartbeatFrequencyMS=10) `
244+ - Run a ping command using C1 and record the ` $clusterTime ` in the response, as ` clusterTime ` .
245+ - ` clusterTime = c1.admin.command({"ping": 1})["$clusterTime"] `
246+ - Using a separate client, C2, run an insert to advance the cluster time
247+ - ` c2.test.test.insert_one({"advance": "$clusterTime"}) `
248+ - Next, wait until the client C1 processes the next pair of SDAM heartbeat started + succeeded events.
249+ - If possible, assert the SDAM heartbeats do not send ` $clusterTime `
250+ - Run a ping command using C1 and assert that ` $clusterTime ` sent is the same as the ` clusterTime ` recorded earlier.
251+ This assertion proves that C1's ` $clusterTime ` was not advanced by gossiping through SDAM.
252+
241253## Changelog
242254
255+ - 2025-02-24: Test drivers do not gossip $clusterTime on SDAM.
243256- 2024-05-08: Migrated from reStructuredText to Markdown.
244257- 2019-05-15: Initial version.
245258- 2021-06-15: Added snapshot-session tests. Introduced legacy and unified folders.
0 commit comments