Skip to content

DRIVERS-1995: Do not error when parsing change stream event documents #1164

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

Closed
wants to merge 3 commits into from

Conversation

JamesKovacs
Copy link
Contributor

Of the two new unified tests, Test server error on projecting out _id, already passes on the .NET/C# driver. The other unified test, Test projection in change stream returns expected fields, fails but I haven't investigated whether this is a test runner bug or an impl bug. When the change stream is run in the shell, it produces the asserted document, but the unified test in the .NET/C# driver does not.

The remaining 3 tests assert compatibility with potential future changes that the server could make. Therefore they have to be written as prose tests asserting that the change stream response parsing machinery can tolerate new operation types, new fields, and changes to the returned ns document.

Thanks in advance for any feedback and suggestions.

@JamesKovacs JamesKovacs requested a review from BorisDog March 28, 2022 23:53
@JamesKovacs JamesKovacs requested a review from a team as a code owner March 28, 2022 23:53
@JamesKovacs JamesKovacs requested review from benjirewis and removed request for a team March 28, 2022 23:53
@JamesKovacs JamesKovacs requested a review from jmikola March 29, 2022 21:48
Comment on lines 194 to 197
document: {
"_id": 1,
"a": 1
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not aware of any other YAML tests that use braces for multiple lines. That said, we do have plenty that use this to be more concise and express a document on a single line, so I'd suggest the following:

Suggested change
document: {
"_id": 1,
"a": 1
}
document: { _id: 1, a: 1 }

Quoting fields also isn't required so I removed that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment on lines 200 to 206
expectResult: {
"operationType": "addedInFutureMongoDBVersion",
"ns": {
"db": "database0",
"coll": "collection0"
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically do not hard-code database and collection names. Since these are already defined as *database0 and *collection0 in the entity definitions, we can reuse those here.

Suggested change
expectResult: {
"operationType": "addedInFutureMongoDBVersion",
"ns": {
"db": "database0",
"coll": "collection0"
}
}
expectResult:
operationType: "addedInFutureMongoDBVersion"
ns: { db: *database0, coll: *collection0 }

Other tests would typically only define &database0 for the entity identifier and then define another &databaseName0 anchor for its name, but that wasn't done in this test file for reasons unknown to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can probably tell, I haven't written a lot of unified spec tests. Thanks for the pointers. Updating the tests as suggested.

arguments:
# using $project to simulate future changes to ChangeStreamDocument structure
pipeline: [ { $project: { operationType: 1, ns: 1, newField: "newFieldValue" } } ]
saveResultAsEntity: &changeStream0 changeStream0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
saveResultAsEntity: &changeStream0 changeStream0
saveResultAsEntity: *changeStream0

No need to redefine the anchor unless you expect this test might be copied to another file. That said, YAML also allows redefinition (last one wins) so feel free to ignore this suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to leave the tests self-contained in case they are re-ordered or split into separate files in the future. As well having an anchor defined in a previous test seems messy to me.

Comment on lines 221 to 224
document: {
"_id": 1,
"a": 1
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
document: {
"_id": 1,
"a": 1
}
document: { _id: 1, a: 1 }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 227 to 234
expectResult: {
"operationType": "insert",
"ns": {
"db": "database0",
"coll": "collection0"
},
"newField": "newFieldValue"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expectResult: {
"operationType": "insert",
"ns": {
"db": "database0",
"coll": "collection0"
},
"newField": "newFieldValue"
}
expectResult:
operationType: "insert"
ns: { db: *database0, coll: *collection0 }
newField: "newFieldValue"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines 302 to 305
document: {
"_id": 1,
"a": 1
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
document: {
"_id": 1,
"a": 1
}
document: { _id: 1, a: 1 }

object: *collection0
arguments:
pipeline: [ { $project: { optype: "$operationType", ns: 1, newField: "value" } } ]
saveResultAsEntity: &changeStream0 changeStream0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
saveResultAsEntity: &changeStream0 changeStream0
saveResultAsEntity: *changeStream0

Comment on lines 326 to 329
document: {
"_id": 1,
"a": 1
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
document: {
"_id": 1,
"a": 1
}
document: { _id: 1, a: 1 }

Comment on lines 332 to 339
expectResult: {
"optype": "insert",
"ns": {
"db": "database0",
"coll": "collection0"
},
"newField": "value"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expectResult: {
"optype": "insert",
"ns": {
"db": "database0",
"coll": "collection0"
},
"newField": "value"
}
expectResult:
optype: "insert",
ns: { db: *database0, coll: *collection0 }
newField: "value"


- description: "Test unknown operationType MUST NOT err"
runOnRequirements:
- minServerVersion: "3.6"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like any of the tests in this file specify a minServerVersion below 3.6 (some use a greater version). If you'd like to clean this up, I'd propose removing minServerVersion: "3.6" throughout the file (both in your new tests and the few existing ones that shared it) and just adding this to the top-level runOnRequirements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

Copy link
Contributor

@benjirewis benjirewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good to me. The new tests all pass in the Go driver as we do not actually parse change stream event documents and instead just pass them around as our bson.Raw type.

Copy link
Contributor Author

@JamesKovacs JamesKovacs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorporated feedback and pushed a new commit.


- description: "Test unknown operationType MUST NOT err"
runOnRequirements:
- minServerVersion: "3.6"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

Comment on lines 194 to 197
document: {
"_id": 1,
"a": 1
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment on lines 200 to 206
expectResult: {
"operationType": "addedInFutureMongoDBVersion",
"ns": {
"db": "database0",
"coll": "collection0"
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can probably tell, I haven't written a lot of unified spec tests. Thanks for the pointers. Updating the tests as suggested.

arguments:
# using $project to simulate future changes to ChangeStreamDocument structure
pipeline: [ { $project: { operationType: 1, ns: 1, newField: "newFieldValue" } } ]
saveResultAsEntity: &changeStream0 changeStream0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to leave the tests self-contained in case they are re-ordered or split into separate files in the future. As well having an anchor defined in a previous test seems messy to me.

Comment on lines 221 to 224
document: {
"_id": 1,
"a": 1
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 227 to 234
expectResult: {
"operationType": "insert",
"ns": {
"db": "database0",
"coll": "collection0"
},
"newField": "newFieldValue"
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

JamesKovacs added a commit to JamesKovacs/specifications that referenced this pull request Mar 31, 2022
@JamesKovacs
Copy link
Contributor Author

Squashed and merged manually due to merge conflicts with change stream updates that got in before me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants