Skip to content

Commit ec3caba

Browse files
test(NODE-6202): use single mongos in unacknowledged write tests (#4149)
Co-authored-by: Aditi Khare <[email protected]>
1 parent c948d9c commit ec3caba

File tree

8 files changed

+298
-12
lines changed

8 files changed

+298
-12
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
{
2+
"description": "unacknowledged-write",
3+
"schemaVersion": "1.16",
4+
"createEntities": [
5+
{
6+
"client": {
7+
"id": "client",
8+
"useMultipleMongoses": false,
9+
"observeLogMessages": {
10+
"command": "debug"
11+
}
12+
}
13+
},
14+
{
15+
"database": {
16+
"id": "database",
17+
"client": "client",
18+
"databaseName": "logging-tests"
19+
}
20+
},
21+
{
22+
"collection": {
23+
"id": "collection",
24+
"database": "database",
25+
"collectionName": "logging-tests-collection",
26+
"collectionOptions": {
27+
"writeConcern": {
28+
"w": 0
29+
}
30+
}
31+
}
32+
}
33+
],
34+
"initialData": [
35+
{
36+
"collectionName": "logging-tests-collection",
37+
"databaseName": "logging-tests",
38+
"documents": [
39+
{
40+
"_id": 1
41+
}
42+
]
43+
}
44+
],
45+
"tests": [
46+
{
47+
"description": "An unacknowledged write generates a succeeded log message with ok: 1 reply",
48+
"operations": [
49+
{
50+
"name": "insertOne",
51+
"object": "collection",
52+
"arguments": {
53+
"document": {
54+
"_id": 2
55+
}
56+
}
57+
},
58+
{
59+
"name": "find",
60+
"object": "collection",
61+
"arguments": {
62+
"filter": {}
63+
},
64+
"expectResult": [
65+
{
66+
"_id": 1
67+
},
68+
{
69+
"_id": 2
70+
}
71+
]
72+
}
73+
],
74+
"expectLogMessages": [
75+
{
76+
"client": "client",
77+
"ignoreExtraMessages": true,
78+
"messages": [
79+
{
80+
"level": "debug",
81+
"component": "command",
82+
"data": {
83+
"message": "Command started",
84+
"databaseName": "logging-tests",
85+
"commandName": "insert",
86+
"command": {
87+
"$$matchAsDocument": {
88+
"$$matchAsRoot": {
89+
"insert": "logging-tests-collection",
90+
"$db": "logging-tests"
91+
}
92+
}
93+
},
94+
"requestId": {
95+
"$$type": [
96+
"int",
97+
"long"
98+
]
99+
},
100+
"serverHost": {
101+
"$$type": "string"
102+
},
103+
"serverPort": {
104+
"$$type": [
105+
"int",
106+
"long"
107+
]
108+
}
109+
}
110+
},
111+
{
112+
"level": "debug",
113+
"component": "command",
114+
"data": {
115+
"message": "Command succeeded",
116+
"commandName": "insert",
117+
"reply": {
118+
"$$matchAsDocument": {
119+
"ok": 1
120+
}
121+
},
122+
"requestId": {
123+
"$$type": [
124+
"int",
125+
"long"
126+
]
127+
},
128+
"serverHost": {
129+
"$$type": "string"
130+
},
131+
"serverPort": {
132+
"$$type": [
133+
"int",
134+
"long"
135+
]
136+
},
137+
"durationMS": {
138+
"$$type": [
139+
"double",
140+
"int",
141+
"long"
142+
]
143+
}
144+
}
145+
}
146+
]
147+
}
148+
]
149+
}
150+
]
151+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
description: "unacknowledged-write"
2+
3+
schemaVersion: "1.16"
4+
5+
createEntities:
6+
- client:
7+
id: &client client
8+
useMultipleMongoses: false
9+
observeLogMessages:
10+
command: debug
11+
- database:
12+
id: &database database
13+
client: *client
14+
databaseName: &databaseName logging-tests
15+
- collection:
16+
id: &collection collection
17+
database: *database
18+
collectionName: &collectionName logging-tests-collection
19+
collectionOptions:
20+
writeConcern: { w: 0 }
21+
22+
initialData:
23+
- collectionName: *collectionName
24+
databaseName: *databaseName
25+
documents:
26+
- { _id: 1 }
27+
28+
tests:
29+
- description: "An unacknowledged write generates a succeeded log message with ok: 1 reply"
30+
operations:
31+
- name: insertOne
32+
object: *collection
33+
arguments:
34+
document: { _id: 2 }
35+
# Force completion of the w: 0 write by executing a find on the same connection
36+
- name: find
37+
object: *collection
38+
arguments:
39+
filter: { }
40+
expectResult: [
41+
{ _id: 1 },
42+
{ _id: 2 }
43+
]
44+
expectLogMessages:
45+
- client: *client
46+
ignoreExtraMessages: true
47+
messages:
48+
- level: debug
49+
component: command
50+
data:
51+
message: "Command started"
52+
databaseName: *databaseName
53+
commandName: insert
54+
command:
55+
$$matchAsDocument:
56+
$$matchAsRoot:
57+
insert: *collectionName
58+
$db: *databaseName
59+
requestId: { $$type: [int, long] }
60+
serverHost: { $$type: string }
61+
serverPort: { $$type: [int, long] }
62+
63+
- level: debug
64+
component: command
65+
data:
66+
message: "Command succeeded"
67+
commandName: insert
68+
reply:
69+
$$matchAsDocument:
70+
ok: 1
71+
requestId: { $$type: [int, long] }
72+
serverHost: { $$type: string }
73+
serverPort: { $$type: [int, long] }
74+
durationMS: { $$type: [double, int, long] }
75+
76+

test/spec/command-logging-and-monitoring/monitoring/unacknowledgedBulkWrite.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"description": "unacknowledgedBulkWrite",
3-
"schemaVersion": "1.0",
3+
"schemaVersion": "1.7",
44
"createEntities": [
55
{
66
"client": {
77
"id": "client",
8+
"useMultipleMongoses": false,
89
"observeEvents": [
910
"commandStartedEvent",
1011
"commandSucceededEvent",
@@ -64,11 +65,29 @@
6465
],
6566
"ordered": false
6667
}
68+
},
69+
{
70+
"name": "find",
71+
"object": "collection",
72+
"arguments": {
73+
"filter": {}
74+
},
75+
"expectResult": [
76+
{
77+
"_id": 1,
78+
"x": 11
79+
},
80+
{
81+
"_id": "unorderedBulkWriteInsertW0",
82+
"x": 44
83+
}
84+
]
6785
}
6886
],
6987
"expectEvents": [
7088
{
7189
"client": "client",
90+
"ignoreExtraEvents": true,
7291
"events": [
7392
{
7493
"commandStartedEvent": {

test/spec/command-logging-and-monitoring/monitoring/unacknowledgedBulkWrite.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
description: "unacknowledgedBulkWrite"
22

3-
schemaVersion: "1.0"
3+
schemaVersion: "1.7"
44

55
createEntities:
66
- client:
77
id: &client client
8+
useMultipleMongoses: false
89
observeEvents:
910
- commandStartedEvent
1011
- commandSucceededEvent
@@ -36,8 +37,18 @@ tests:
3637
- insertOne:
3738
document: { _id: "unorderedBulkWriteInsertW0", x: 44 }
3839
ordered: false
40+
# Force completion of the w: 0 write by executing a find on the same connection
41+
- name: find
42+
object: *collection
43+
arguments:
44+
filter: { }
45+
expectResult: [
46+
{ _id: 1, x: 11 },
47+
{ _id: "unorderedBulkWriteInsertW0", x: 44 }
48+
]
3949
expectEvents:
4050
- client: *client
51+
ignoreExtraEvents: true
4152
events:
4253
- commandStartedEvent:
4354
command:

test/tools/unified-spec-runner/match.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,13 @@ export function resultCheck(
241241
}
242242
for (const [index, value] of expectedEntries) {
243243
path.push(`[${index}]`);
244-
checkNestedDocuments(index, value, false);
244+
checkNestedDocuments(index, value, checkExtraKeys);
245245
path.pop();
246246
}
247247
} else {
248248
for (const [key, value] of expectedEntries) {
249249
path.push(`.${key}`);
250-
checkNestedDocuments(key, value, true);
250+
checkNestedDocuments(key, value, checkExtraKeys);
251251
path.pop();
252252
}
253253

@@ -361,7 +361,7 @@ export function specialCheck(
361361
} else if (isMatchAsDocumentOperator(expected)) {
362362
if (typeof actual === 'string') {
363363
const actualDoc = EJSON.parse(actual, { relaxed: false });
364-
resultCheck(actualDoc, expected.$$matchAsDocument as any, entities, path, true);
364+
resultCheck(actualDoc, expected.$$matchAsDocument as any, entities, path, checkExtraKeys);
365365
} else {
366366
expect.fail(
367367
`Expected value at path '${path.join('')}' to be string, but received ${inspect(actual)}`
@@ -650,7 +650,7 @@ export function matchesEvents(
650650
}
651651
}
652652

653-
export function filterExtraLogs(
653+
export function filterIgnoredMessages(
654654
logsToIgnore: ExpectedLogMessage[],
655655
actual: ExpectedLogMessage[],
656656
entities: EntitiesMap
@@ -675,11 +675,16 @@ export function filterExtraLogs(
675675
export function compareLogs(
676676
expected: ExpectedLogMessage[],
677677
actual: ExpectedLogMessage[],
678-
entities: EntitiesMap
678+
entities: EntitiesMap,
679+
ignoreExtraMessages = false
679680
): void {
680-
expect(actual).to.have.lengthOf(expected.length);
681+
if (!ignoreExtraMessages) {
682+
expect(actual).to.have.lengthOf(expected.length);
683+
}
681684

682685
for (const [index, actualLog] of actual.entries()) {
686+
if (index >= expected.length && ignoreExtraMessages) return;
687+
683688
const rootPrefix = `expectLogMessages[${index}]`;
684689
const expectedLog = expected[index];
685690

test/tools/unified-spec-runner/runner.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { MONGODB_ERROR_CODES, ns, ReadPreference, TopologyType } from '../../mon
77
import { ejson } from '../utils';
88
import { AstrolabeResultsWriter } from './astrolabe_results_writer';
99
import { EntitiesMap, type UnifiedMongoClient } from './entities';
10-
import { compareLogs, filterExtraLogs, matchesEvents } from './match';
10+
import { compareLogs, filterIgnoredMessages, matchesEvents } from './match';
1111
import { executeOperationAndCheck } from './operations';
1212
import * as uni from './schema';
1313
import { isAnyRequirementSatisfied, patchVersion, zip } from './unified-utils';
@@ -247,13 +247,18 @@ async function runUnifiedTest(
247247

248248
expect(testClient, `No client entity found with id ${clientId}`).to.exist;
249249
const filteredTestClientLogs = expectedLogsForClient.ignoreMessages
250-
? filterExtraLogs(
250+
? filterIgnoredMessages(
251251
expectedLogsForClient.ignoreMessages,
252252
testClient!.collectedLogs,
253253
entities
254254
)
255255
: testClient!.collectedLogs;
256-
compareLogs(expectedLogsForClient.messages, filteredTestClientLogs, entities);
256+
compareLogs(
257+
expectedLogsForClient.messages,
258+
filteredTestClientLogs,
259+
entities,
260+
expectedLogsForClient.ignoreExtraMessages
261+
);
257262
}
258263
}
259264

0 commit comments

Comments
 (0)