Skip to content

Commit 45fd51e

Browse files
authored
RUST-2188 Update sessions spec test (#1419)
1 parent d669596 commit 45fd51e

File tree

3 files changed

+52
-31
lines changed

3 files changed

+52
-31
lines changed

src/test/spec/json/sessions/README.md

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6462
Repeat 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

194192
This 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.

src/test/spec/json/sessions/driver-sessions-dirty-session-errors.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,9 @@
347347
"x": 1
348348
}
349349
},
350-
"new": false,
350+
"new": {
351+
"$$unsetOrMatches": false
352+
},
351353
"lsid": {
352354
"$$sessionLsid": "session0"
353355
},
@@ -375,7 +377,9 @@
375377
"x": 1
376378
}
377379
},
378-
"new": false,
380+
"new": {
381+
"$$unsetOrMatches": false
382+
},
379383
"lsid": {
380384
"$$sessionLsid": "session0"
381385
},
@@ -627,7 +631,9 @@
627631
"x": 1
628632
}
629633
},
630-
"new": false,
634+
"new": {
635+
"$$unsetOrMatches": false
636+
},
631637
"lsid": {
632638
"$$type": "object"
633639
},
@@ -655,7 +661,9 @@
655661
"x": 1
656662
}
657663
},
658-
"new": false,
664+
"new": {
665+
"$$unsetOrMatches": false
666+
},
659667
"lsid": {
660668
"$$type": "object"
661669
},

src/test/spec/json/sessions/driver-sessions-dirty-session-errors.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ tests:
164164
findAndModify: *collection0Name
165165
query: { _id: 1 }
166166
update: { $inc: { x: 1 } }
167-
new: false
167+
new: { $$unsetOrMatches: false }
168168
lsid: { $$sessionLsid: *session0 }
169169
txnNumber: 1
170170
readConcern: { $$exists: false }
@@ -255,7 +255,7 @@ tests:
255255
findAndModify: *collection0Name
256256
query: { _id: 1 }
257257
update: { $inc: { x: 1 } }
258-
new: false
258+
new: { $$unsetOrMatches: false }
259259
lsid: { $$type: object }
260260
txnNumber: 1
261261
readConcern: { $$exists: false }

0 commit comments

Comments
 (0)