Skip to content

Commit e281c16

Browse files
authored
RUST-2096 Split updateWithPipelines tests (#1344)
1 parent 458228f commit e281c16

20 files changed

+1427
-1070
lines changed

src/test/spec/crud.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ async fn run_unified() {
3232
// Unacknowledged write; see above.
3333
"Unacknowledged write using dollar-prefixed or dotted keys may be silently rejected on \
3434
pre-5.0 server",
35+
"Requesting unacknowledged write with verboseResults is a client-side error",
36+
"Requesting unacknowledged write with ordered is a client-side error",
3537
// TODO RUST-663: Unskip these tests.
3638
"Aggregate with $out includes read preference for 5.0+ server",
3739
"Aggregate with $out omits read preference for pre-5.0 server",

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

Lines changed: 67 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -370,54 +370,15 @@ Assert that a CommandStartedEvent was observed for the `killCursors` command.
370370

371371
### 10. `MongoClient.bulkWrite` returns error for unacknowledged too-large insert
372372

373-
This test must only be run on 8.0+ servers. This test must be skipped on Atlas Serverless.
374-
375-
Construct a `MongoClient` (referred to as `client`).
376-
377-
Perform a `hello` command using `client` and record the following values from the response: `maxBsonObjectSize`.
378-
379-
Then, construct the following document (referred to as `document`):
380-
381-
```javascript
382-
{
383-
"a": "b".repeat(maxBsonObjectSize)
384-
}
385-
```
373+
Removed.
386374

387375
#### With insert
388376

389-
Construct the following write model (referred to as `model`):
390-
391-
```javascript
392-
InsertOne: {
393-
"namespace": "db.coll",
394-
"document": document
395-
}
396-
```
397-
398-
Construct as list of write models (referred to as `models`) with the one `model`.
399-
400-
Call `MongoClient.bulkWrite` with `models` and `BulkWriteOptions.writeConcern` set to an unacknowledged write concern.
401-
402-
Expect a client-side error due the size.
377+
Removed.
403378

404379
#### With replace
405380

406-
Construct the following write model (referred to as `model`):
407-
408-
```javascript
409-
ReplaceOne: {
410-
"namespace": "db.coll",
411-
"filter": {},
412-
"replacement": document
413-
}
414-
```
415-
416-
Construct as list of write models (referred to as `models`) with the one `model`.
417-
418-
Call `MongoClient.bulkWrite` with `models` and `BulkWriteOptions.writeConcern` set to an unacknowledged write concern.
419-
420-
Expect a client-side error due the size.
381+
Removed.
421382

422383
### 11. `MongoClient.bulkWrite` batch splits when the addition of a new namespace exceeds the maximum message size
423384

@@ -437,7 +398,7 @@ CommandStartedEvents. Perform a `hello` command using `client` and record the fo
437398

438399
Calculate the following values:
439400

440-
```
401+
```javascript
441402
opsBytes = maxMessageSizeBytes - 1122
442403
numModels = opsBytes / maxBsonObjectSize
443404
remainderBytes = opsBytes % maxBsonObjectSize
@@ -493,7 +454,7 @@ Assert that the namespace contained in `event.command.nsInfo` is "db.coll".
493454

494455
Construct the following namespace (referred to as `namespace`):
495456

496-
```
457+
```javascript
497458
"db." + "c".repeat(200)
498459
```
499460

@@ -533,19 +494,19 @@ changed in the bulk write specification.
533494

534495
The command document for the `bulkWrite` has the following structure and size:
535496

536-
```javascript
497+
```typescript
537498
{
538499
"bulkWrite": 1,
539500
"errorsOnly": true,
540501
"ordered": true
541502
}
542503

543-
Size: 43 bytes
504+
// Size: 43 bytes
544505
```
545506

546507
Each write model will create an `ops` document with the following structure and size:
547508

548-
```javascript
509+
```typescript
549510
{
550511
"insert": <0 | 1>,
551512
"document": {
@@ -554,7 +515,7 @@ Each write model will create an `ops` document with the following structure and
554515
}
555516
}
556517

557-
Size: 57 bytes + <number of characters in string>
518+
// Size: 57 bytes + <number of characters in string>
558519
```
559520

560521
The `ops` document for both `newNamespaceModel` and `sameNamespaceModel` has a string with one character, so it is a
@@ -567,7 +528,7 @@ The models using the "db.coll" namespace will create one `nsInfo` document with
567528
"ns": "db.coll"
568529
}
569530

570-
Size: 21 bytes
531+
// Size: 21 bytes
571532
```
572533

573534
`newNamespaceModel` will create an `nsInfo` document with the following structure and size:
@@ -577,13 +538,13 @@ Size: 21 bytes
577538
"ns": "db.<c repeated 200 times>"
578539
}
579540

580-
Size: 217 bytes
541+
// Size: 217 bytes
581542
```
582543

583544
We need to fill up the rest of the message with bytes such that another `ops` document will fit, but another `nsInfo`
584545
entry will not. The following calculations are used:
585546

586-
```
547+
```python
587548
# 1000 is the OP_MSG overhead required in the spec
588549
maxBulkWriteBytes = maxMessageSizeBytes - 1000
589550

@@ -628,7 +589,7 @@ Assert that `error` is a client error.
628589

629590
Construct the following namespace (referred to as `namespace`):
630591

631-
```
592+
```javascript
632593
"db." + "c".repeat(maxMessageSizeBytes)
633594
```
634595

@@ -693,3 +654,57 @@ maxTimeMS value of 2000ms for the `explain`.
693654

694655
Obtain the command started event for the explain. Confirm that the top-level explain command should has a `maxTimeMS`
695656
value of `2000`.
657+
658+
### 15. `MongoClient.bulkWrite` with unacknowledged write concern uses `w:0` for all batches
659+
660+
This test must only be run on 8.0+ servers. This test must be skipped on Atlas Serverless.
661+
662+
If testing with a sharded cluster, only connect to one mongos. This is intended to ensure the `countDocuments` operation
663+
uses the same connection as the `bulkWrite` to get the correct connection count. (See
664+
[DRIVERS-2921](https://jira.mongodb.org/browse/DRIVERS-2921)).
665+
666+
Construct a `MongoClient` (referred to as `client`) with
667+
[command monitoring](../../command-logging-and-monitoring/command-logging-and-monitoring.md) enabled to observe
668+
CommandStartedEvents. Perform a `hello` command using `client` and record the `maxBsonObjectSize` and
669+
`maxMessageSizeBytes` values in the response.
670+
671+
Construct a `MongoCollection` (referred to as `coll`) for the collection "db.coll". Drop `coll`.
672+
673+
Use the `create` command to create "db.coll" to workaround [SERVER-95537](https://jira.mongodb.org/browse/SERVER-95537).
674+
675+
Construct the following write model (referred to as `model`):
676+
677+
```javascript
678+
InsertOne: {
679+
"namespace": "db.coll",
680+
"document": { "a": "b".repeat(maxBsonObjectSize - 500) }
681+
}
682+
```
683+
684+
Construct a list of write models (referred to as `models`) with `model` repeated
685+
`maxMessageSizeBytes / maxBsonObjectSize + 1` times.
686+
687+
Call `client.bulkWrite` with `models`. Pass `BulkWriteOptions` with `ordered` set to `false` and `writeConcern` set to
688+
an unacknowledged write concern. Assert no error occurred. Assert the result indicates the write was unacknowledged.
689+
690+
Assert that two CommandStartedEvents (referred to as `firstEvent` and `secondEvent`) were observed for the `bulkWrite`
691+
command. Assert that the length of `firstEvent.command.ops` is `maxMessageSizeBytes / maxBsonObjectSize`. Assert that
692+
the length of `secondEvent.command.ops` is 1. If the driver exposes `operationId`s in its CommandStartedEvents, assert
693+
that `firstEvent.operationId` is equal to `secondEvent.operationId`. Assert both commands include
694+
`writeConcern: {w: 0}`.
695+
696+
To force completion of the `w:0` writes, execute `coll.countDocuments` and expect the returned count is
697+
`maxMessageSizeBytes / maxBsonObjectSize + 1`. This is intended to avoid incomplete writes interfering with other tests
698+
that may use this collection.
699+
700+
### 16. Generated document identifiers are the first field in their document
701+
702+
Construct a `MongoClient` (referred to as `client`) with
703+
[command monitoring](../../command-logging-and-monitoring/command-logging-and-monitoring.md) enabled to observe
704+
CommandStartedEvents. For each of `insertOne`, client `bulkWrite`, and collection `bulkWrite`, do the following:
705+
706+
- Execute the command with a document that does not contain an `_id` field.
707+
- If possible, capture the wire protocol message (referred to as `request`) of the command and assert that the first
708+
field of `request.documents[0]` is `_id`.
709+
- Otherwise, capture the CommandStartedEvent (referred to as `event`) emitted by the command and assert that the first
710+
field of `event.command.documents[0]` is `_id`.
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
{
2+
"description": "bulkWrite-updateMany-pipeline",
3+
"schemaVersion": "1.0",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "4.1.11"
7+
}
8+
],
9+
"createEntities": [
10+
{
11+
"client": {
12+
"id": "client0",
13+
"observeEvents": [
14+
"commandStartedEvent"
15+
]
16+
}
17+
},
18+
{
19+
"database": {
20+
"id": "database0",
21+
"client": "client0",
22+
"databaseName": "crud-tests"
23+
}
24+
},
25+
{
26+
"collection": {
27+
"id": "collection0",
28+
"database": "database0",
29+
"collectionName": "test"
30+
}
31+
}
32+
],
33+
"initialData": [
34+
{
35+
"collectionName": "test",
36+
"databaseName": "crud-tests",
37+
"documents": [
38+
{
39+
"_id": 1,
40+
"x": 1,
41+
"y": 1,
42+
"t": {
43+
"u": {
44+
"v": 1
45+
}
46+
}
47+
},
48+
{
49+
"_id": 2,
50+
"x": 2,
51+
"y": 1
52+
}
53+
]
54+
}
55+
],
56+
"tests": [
57+
{
58+
"description": "UpdateMany in bulk write using pipelines",
59+
"operations": [
60+
{
61+
"object": "collection0",
62+
"name": "bulkWrite",
63+
"arguments": {
64+
"requests": [
65+
{
66+
"updateMany": {
67+
"filter": {},
68+
"update": [
69+
{
70+
"$project": {
71+
"x": 1
72+
}
73+
},
74+
{
75+
"$addFields": {
76+
"foo": 1
77+
}
78+
}
79+
]
80+
}
81+
}
82+
]
83+
},
84+
"expectResult": {
85+
"matchedCount": 2,
86+
"modifiedCount": 2,
87+
"upsertedCount": 0
88+
}
89+
}
90+
],
91+
"expectEvents": [
92+
{
93+
"client": "client0",
94+
"events": [
95+
{
96+
"commandStartedEvent": {
97+
"command": {
98+
"update": "test",
99+
"updates": [
100+
{
101+
"q": {},
102+
"u": [
103+
{
104+
"$project": {
105+
"x": 1
106+
}
107+
},
108+
{
109+
"$addFields": {
110+
"foo": 1
111+
}
112+
}
113+
],
114+
"multi": true,
115+
"upsert": {
116+
"$$unsetOrMatches": false
117+
}
118+
}
119+
]
120+
},
121+
"commandName": "update",
122+
"databaseName": "crud-tests"
123+
}
124+
}
125+
]
126+
}
127+
],
128+
"outcome": [
129+
{
130+
"collectionName": "test",
131+
"databaseName": "crud-tests",
132+
"documents": [
133+
{
134+
"_id": 1,
135+
"x": 1,
136+
"foo": 1
137+
},
138+
{
139+
"_id": 2,
140+
"x": 2,
141+
"foo": 1
142+
}
143+
]
144+
}
145+
]
146+
}
147+
]
148+
}

0 commit comments

Comments
 (0)