From 5262ba1a63d91d996c0762d890b25497fb8cf1c1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 1 Jul 2019 21:15:20 -0400 Subject: [PATCH 1/2] SPEC-1221 Reinstate DuplicateKey code assertions in error labels tests --- .../transactions-convenient-api/tests/callback-retry.json | 3 ++- source/transactions-convenient-api/tests/callback-retry.yml | 6 +++--- source/transactions/tests/abort.json | 3 ++- source/transactions/tests/abort.yml | 6 +++--- source/transactions/tests/error-labels.json | 3 ++- source/transactions/tests/error-labels.yml | 6 +++--- 6 files changed, 15 insertions(+), 12 deletions(-) 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 From 471145a3e9c914f4c019a95fdf553a66aa0b7a6e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 23 Sep 2019 18:07:32 -0400 Subject: [PATCH 2/2] Add the note about exception message text --- source/crud/tests/README.rst | 9 +++++++++ 1 file changed, 9 insertions(+) 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 ==========================