Skip to content

test(NODE-6202): use single mongos in unacknowledged write tests #4149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"description": "unacknowledged-write",
"schemaVersion": "1.16",
"createEntities": [
{
"client": {
"id": "client",
"useMultipleMongoses": false,
"observeLogMessages": {
"command": "debug"
}
}
},
{
"database": {
"id": "database",
"client": "client",
"databaseName": "logging-tests"
}
},
{
"collection": {
"id": "collection",
"database": "database",
"collectionName": "logging-tests-collection",
"collectionOptions": {
"writeConcern": {
"w": 0
}
}
}
}
],
"initialData": [
{
"collectionName": "logging-tests-collection",
"databaseName": "logging-tests",
"documents": [
{
"_id": 1
}
]
}
],
"tests": [
{
"description": "An unacknowledged write generates a succeeded log message with ok: 1 reply",
"operations": [
{
"name": "insertOne",
"object": "collection",
"arguments": {
"document": {
"_id": 2
}
}
},
{
"name": "find",
"object": "collection",
"arguments": {
"filter": {}
},
"expectResult": [
{
"_id": 1
},
{
"_id": 2
}
]
}
],
"expectLogMessages": [
{
"client": "client",
"ignoreExtraMessages": true,
"messages": [
{
"level": "debug",
"component": "command",
"data": {
"message": "Command started",
"databaseName": "logging-tests",
"commandName": "insert",
"command": {
"$$matchAsDocument": {
"$$matchAsRoot": {
"insert": "logging-tests-collection",
"$db": "logging-tests"
}
}
},
"requestId": {
"$$type": [
"int",
"long"
]
},
"serverHost": {
"$$type": "string"
},
"serverPort": {
"$$type": [
"int",
"long"
]
}
}
},
{
"level": "debug",
"component": "command",
"data": {
"message": "Command succeeded",
"commandName": "insert",
"reply": {
"$$matchAsDocument": {
"ok": 1
}
},
"requestId": {
"$$type": [
"int",
"long"
]
},
"serverHost": {
"$$type": "string"
},
"serverPort": {
"$$type": [
"int",
"long"
]
},
"durationMS": {
"$$type": [
"double",
"int",
"long"
]
}
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
description: "unacknowledged-write"

schemaVersion: "1.16"

createEntities:
- client:
id: &client client
useMultipleMongoses: false
observeLogMessages:
command: debug
- database:
id: &database database
client: *client
databaseName: &databaseName logging-tests
- collection:
id: &collection collection
database: *database
collectionName: &collectionName logging-tests-collection
collectionOptions:
writeConcern: { w: 0 }

initialData:
- collectionName: *collectionName
databaseName: *databaseName
documents:
- { _id: 1 }

tests:
- description: "An unacknowledged write generates a succeeded log message with ok: 1 reply"
operations:
- name: insertOne
object: *collection
arguments:
document: { _id: 2 }
# Force completion of the w: 0 write by executing a find on the same connection
- name: find
object: *collection
arguments:
filter: { }
expectResult: [
{ _id: 1 },
{ _id: 2 }
]
expectLogMessages:
- client: *client
ignoreExtraMessages: true
messages:
- level: debug
component: command
data:
message: "Command started"
databaseName: *databaseName
commandName: insert
command:
$$matchAsDocument:
$$matchAsRoot:
insert: *collectionName
$db: *databaseName
requestId: { $$type: [int, long] }
serverHost: { $$type: string }
serverPort: { $$type: [int, long] }

- level: debug
component: command
data:
message: "Command succeeded"
commandName: insert
reply:
$$matchAsDocument:
ok: 1
requestId: { $$type: [int, long] }
serverHost: { $$type: string }
serverPort: { $$type: [int, long] }
durationMS: { $$type: [double, int, long] }


Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"description": "unacknowledgedBulkWrite",
"schemaVersion": "1.0",
"schemaVersion": "1.7",
"createEntities": [
{
"client": {
"id": "client",
"useMultipleMongoses": false,
"observeEvents": [
"commandStartedEvent",
"commandSucceededEvent",
Expand Down Expand Up @@ -64,11 +65,29 @@
],
"ordered": false
}
},
{
"name": "find",
"object": "collection",
"arguments": {
"filter": {}
},
"expectResult": [
{
"_id": 1,
"x": 11
},
{
"_id": "unorderedBulkWriteInsertW0",
"x": 44
}
]
}
],
"expectEvents": [
{
"client": "client",
"ignoreExtraEvents": true,
"events": [
{
"commandStartedEvent": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
description: "unacknowledgedBulkWrite"

schemaVersion: "1.0"
schemaVersion: "1.7"

createEntities:
- client:
id: &client client
useMultipleMongoses: false
observeEvents:
- commandStartedEvent
- commandSucceededEvent
Expand Down Expand Up @@ -36,8 +37,18 @@ tests:
- insertOne:
document: { _id: "unorderedBulkWriteInsertW0", x: 44 }
ordered: false
# Force completion of the w: 0 write by executing a find on the same connection
- name: find
object: *collection
arguments:
filter: { }
expectResult: [
{ _id: 1, x: 11 },
{ _id: "unorderedBulkWriteInsertW0", x: 44 }
]
expectEvents:
- client: *client
ignoreExtraEvents: true
events:
- commandStartedEvent:
command:
Expand Down
17 changes: 11 additions & 6 deletions test/tools/unified-spec-runner/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,13 @@ export function resultCheck(
}
for (const [index, value] of expectedEntries) {
path.push(`[${index}]`);
checkNestedDocuments(index, value, false);
checkNestedDocuments(index, value, checkExtraKeys);
path.pop();
}
} else {
for (const [key, value] of expectedEntries) {
path.push(`.${key}`);
checkNestedDocuments(key, value, true);
checkNestedDocuments(key, value, checkExtraKeys);
path.pop();
}

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

export function filterExtraLogs(
export function filterIgnoredMessages(
logsToIgnore: ExpectedLogMessage[],
actual: ExpectedLogMessage[],
entities: EntitiesMap
Expand All @@ -675,11 +675,16 @@ export function filterExtraLogs(
export function compareLogs(
expected: ExpectedLogMessage[],
actual: ExpectedLogMessage[],
entities: EntitiesMap
entities: EntitiesMap,
ignoreExtraMessages = false
): void {
expect(actual).to.have.lengthOf(expected.length);
if (!ignoreExtraMessages) {
expect(actual).to.have.lengthOf(expected.length);
}

for (const [index, actualLog] of actual.entries()) {
if (index >= expected.length && ignoreExtraMessages) return;

const rootPrefix = `expectLogMessages[${index}]`;
const expectedLog = expected[index];

Expand Down
11 changes: 8 additions & 3 deletions test/tools/unified-spec-runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MONGODB_ERROR_CODES, ns, ReadPreference, TopologyType } from '../../mon
import { ejson } from '../utils';
import { AstrolabeResultsWriter } from './astrolabe_results_writer';
import { EntitiesMap, type UnifiedMongoClient } from './entities';
import { compareLogs, filterExtraLogs, matchesEvents } from './match';
import { compareLogs, filterIgnoredMessages, matchesEvents } from './match';
import { executeOperationAndCheck } from './operations';
import * as uni from './schema';
import { isAnyRequirementSatisfied, patchVersion, zip } from './unified-utils';
Expand Down Expand Up @@ -247,13 +247,18 @@ async function runUnifiedTest(

expect(testClient, `No client entity found with id ${clientId}`).to.exist;
const filteredTestClientLogs = expectedLogsForClient.ignoreMessages
? filterExtraLogs(
? filterIgnoredMessages(
expectedLogsForClient.ignoreMessages,
testClient!.collectedLogs,
entities
)
: testClient!.collectedLogs;
compareLogs(expectedLogsForClient.messages, filteredTestClientLogs, entities);
compareLogs(
expectedLogsForClient.messages,
filteredTestClientLogs,
entities,
expectedLogsForClient.ignoreExtraMessages
);
}
}

Expand Down
Loading