diff --git a/source/crud/tests/README.rst b/source/crud/tests/README.rst index a912e7d599..50e76f3e69 100644 --- a/source/crud/tests/README.rst +++ b/source/crud/tests/README.rst @@ -160,6 +160,15 @@ The legacy format should not conflict with the newer, multi-operation format used by other specs (e.g. Transactions). It is possible to create a unified test runner capable of executing both formats (as some drivers do). +Error Assertions for Bulk Write Operations +========================================== + +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. + Test Runner Implementation ========================== diff --git a/source/transactions-convenient-api/tests/callback-retry.json b/source/transactions-convenient-api/tests/callback-retry.json index ed36434452..a0391c1b5d 100644 --- a/source/transactions-convenient-api/tests/callback-retry.json +++ b/source/transactions-convenient-api/tests/callback-retry.json @@ -235,7 +235,8 @@ "errorLabelsOmit": [ "TransientTransactionError", "UnknownTransactionCommitResult" - ] + ], + "errorContains": "E11000" } } ], diff --git a/source/transactions-convenient-api/tests/callback-retry.yml b/source/transactions-convenient-api/tests/callback-retry.yml index ca0342a359..edff016bdb 100644 --- a/source/transactions-convenient-api/tests/callback-retry.yml +++ b/source/transactions-convenient-api/tests/callback-retry.yml @@ -160,10 +160,10 @@ tests: result: errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"] result: - # Don't assert on errorCodeName because (after SERVER-38583) the - # DuplicateKey is reported in writeErrors, not as a top-level - # command error. errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"] + # DuplicateKey error code included in the bulk write error message + # returned by the server + errorContains: E11000 expectations: - command_started_event: diff --git a/source/transactions/tests/abort.json b/source/transactions/tests/abort.json index 821a15afbe..3729a98298 100644 --- a/source/transactions/tests/abort.json +++ b/source/transactions/tests/abort.json @@ -458,7 +458,8 @@ "errorLabelsOmit": [ "TransientTransactionError", "UnknownTransactionCommitResult" - ] + ], + "errorContains": "E11000" } }, { diff --git a/source/transactions/tests/abort.yml b/source/transactions/tests/abort.yml index 9b3bc6e442..aa79043232 100644 --- a/source/transactions/tests/abort.yml +++ b/source/transactions/tests/abort.yml @@ -305,10 +305,10 @@ tests: document: _id: 1 result: - # Don't assert on errorCodeName because (after SERVER-38583) the - # DuplicateKey is reported in writeErrors, not as a top-level - # command error. errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"] + # DuplicateKey error code included in the bulk write error message + # returned by the server + errorContains: E11000 # Make sure the server aborted the transaction. - name: insertOne object: collection diff --git a/source/transactions/tests/error-labels.json b/source/transactions/tests/error-labels.json index 3e2451ade8..8662b6d76d 100644 --- a/source/transactions/tests/error-labels.json +++ b/source/transactions/tests/error-labels.json @@ -42,7 +42,8 @@ "errorLabelsOmit": [ "TransientTransactionError", "UnknownTransactionCommitResult" - ] + ], + "errorContains": "E11000" } }, { diff --git a/source/transactions/tests/error-labels.yml b/source/transactions/tests/error-labels.yml index 5c8b428e17..840b603f37 100644 --- a/source/transactions/tests/error-labels.yml +++ b/source/transactions/tests/error-labels.yml @@ -25,10 +25,10 @@ tests: - _id: 1 - _id: 1 result: - # Don't assert on errorCodeName because (after SERVER-38583) the - # DuplicateKey is reported in writeErrors, not as a top-level - # command error. errorLabelsOmit: ["TransientTransactionError", "UnknownTransactionCommitResult"] + # DuplicateKey error code included in the bulk write error message + # returned by the server + errorContains: E11000 - name: abortTransaction object: session0