Skip to content

Conversation

@p-mongo
Copy link
Contributor

@p-mongo p-mongo commented Jul 2, 2019

No description provided.

@jmikola
Copy link
Member

jmikola commented Jul 2, 2019

Is there an issue number for this PR?

@p-mongo
Copy link
Contributor Author

p-mongo commented Jul 2, 2019

@jmikola This goes with the discussion we were having in https://jira.mongodb.org/browse/SERVER-39706 with James.

@p-mongo p-mongo changed the title Reinstate DuplicateKey code assertion in error labels test [wip] Reinstate DuplicateKey code assertion in error labels test Jul 2, 2019
@ShaneHarvey
Copy link
Member

#482 was the previous change that removed the DuplicateKey code name assertions. If we're going to add them back in the "E11000" form can you add them to all the other tests too?

@p-mongo
Copy link
Contributor Author

p-mongo commented Jul 10, 2019

I can do that if there is consensus that the change in this PR is wanted.

@jmikola
Copy link
Member

jmikola commented Jul 11, 2019

I don't have objections if errorContains: "E11000" is truly a portable solution. I suppose it still requires drivers to populate the top-level exception/error message with the string from the write error, which may not be dictated by any spec (although it's likely all drivers are consistent here).

I appreciate the desire to be strict here. Although the operations make it clear that we're causing a duplicate key exception, we can't really be sure without inspecting the error.

@p-mongo p-mongo force-pushed the reinstate-duplicate-key branch from 1814b2e to 344fe91 Compare September 9, 2019 21:23
@p-mongo p-mongo changed the title [wip] Reinstate DuplicateKey code assertion in error labels test SPEC-1221 Reinstate DuplicateKey code assertion in error labels test Sep 9, 2019
@p-mongo p-mongo force-pushed the reinstate-duplicate-key branch from 344fe91 to fa943da Compare September 9, 2019 21:29
@p-mongo p-mongo force-pushed the reinstate-duplicate-key branch from fa943da to 5262ba1 Compare September 13, 2019 20:51
@p-mongo p-mongo changed the title SPEC-1221 Reinstate DuplicateKey code assertion in error labels test SPEC-1221 Reinstate DuplicateKey code assertions in error labels tests Sep 13, 2019
@p-mongo
Copy link
Contributor Author

p-mongo commented Sep 13, 2019

Updated all test files as requested by @ShaneHarvey .

Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

LGTM. Over to @ShaneHarvey.

Copy link
Member

@ShaneHarvey ShaneHarvey left a comment

Choose a reason for hiding this comment

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

LGTM, tested in python: https://evergreen.mongodb.com/version/5d7fc2710305b931eb9a230c

Note that I had to make a small test code change to the "assertErrorContains" logic to look inside our BulkWriteException class otherwise the test would fail with AssertionError: 'e11000' not found in 'batch op errors occurred'.

@p-mongo
Copy link
Contributor Author

p-mongo commented Sep 16, 2019

That is expected since the error was moved from top level to the bulk write errors.

@p-mongo
Copy link
Contributor Author

p-mongo commented Sep 16, 2019

https://github.com/mongodb/specifications/tree/master/source/crud/tests mentions BulkWriteException but not errorContains, should I add a description for errorContains there as part of this PR?

@p-mongo p-mongo requested review from jyemin and mbroadst September 16, 2019 17:40
@ShaneHarvey
Copy link
Member

I don't think we need to add errorContains to the crud spec. It's described in https://github.com/mongodb/specifications/blob/master/source/transactions/tests/README.rst

@jyemin jyemin removed their request for review September 16, 2019 20:54
@jmikola
Copy link
Member

jmikola commented Sep 17, 2019

I don't think we need to add errorContains to the crud spec. It's described in https://github.com/mongodb/specifications/blob/master/source/transactions/tests/README.rst

I think we should err on the side of having each spec document the test fields it actually uses, until we actually have a unified format in place.

That said, this PR didn't actually modify any CRUD test files so I'm a bit confused by @p-mongo's question of adding a note in this comment.

@ShaneHarvey, was this comment referring to you needing to add the BulkWriteException inspection to your transactions spec test runner? If so, perhaps we should add a note about that to the transactions spec test README.

@ShaneHarvey
Copy link
Member

was this comment referring to you needing to add the BulkWriteException inspection to your transactions spec test runner? If so, perhaps we should add a note about that to the transactions spec test README.

Yes it was. I just remembered that BulkWriteException is part of the crud spec. Maybe we can add somethign like this to the errorContains doc:

If the result document has an "errorContains" field, verify that the method threw an exception or returned an error, and that the value of the "errorContains" field matches the error string. "errorContains" is a substring (case-insensitive) of the actual error message. If the actual error is a BulkWriteException then the error string should be checked against the writeConcernError and writeErrors fields.

@jmikola
Copy link
Member

jmikola commented Sep 19, 2019

The transaction test format docs already say that "errorContains" is " A substring of the expected error message.", so I think we could get by with amending the docs for the result element itself. Also consider that errorCodeName is another field that could conceivably apply to an error within a BulkWriteException (rather than the error itself).

That said, I believe some drivers create the BulkWriteException by concatenating the errors within it, in which case some drivers may not even care about this. It's still worth noting in the README, though.

result currently states:

The return value from the operation, if any. This field may be a single document or an array of documents in the case of a multi-document read. If the operation is expected to return an error, the result is a single document that has one or more of the following fields:

I'd propose the following note section after the test format syntax:

Error Assertions for Bulk Write Operations
``... (more backticks, omitted here due to Markdown issues)

When asserting errors (e.g. `errorContains`, `errorCodeName`) for bulk write
operations, the test harness should inspect the `writeConcernError` and/or
`writeErrors` properties of the bulk write exception. This may not be needed for
`errorContains` if a driver concatenates all write and write concern error
messages into the bulk write exception's top-level message.

I didn't mention anything about error labels, but I don't think those would apply to writeConcernError or writeErrors since labels are meant for the top-level exception.

@p-mongo
Copy link
Contributor Author

p-mongo commented Sep 23, 2019

Added the suggested note.

Copy link
Member

@ShaneHarvey ShaneHarvey left a comment

Choose a reason for hiding this comment

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

Still LGTM.

@p-mongo p-mongo merged commit f5983a4 into mongodb:master Sep 24, 2019
@p-mongo p-mongo deleted the reinstate-duplicate-key branch September 24, 2019 21:58
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