summaryrefslogtreecommitdiff
path: root/jstests/core/write/write_error_message_truncation.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core/write/write_error_message_truncation.js')
-rw-r--r--jstests/core/write/write_error_message_truncation.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/jstests/core/write/write_error_message_truncation.js b/jstests/core/write/write_error_message_truncation.js
new file mode 100644
index 00000000000..3a7a33ec86f
--- /dev/null
+++ b/jstests/core/write/write_error_message_truncation.js
@@ -0,0 +1,42 @@
+/**
+ * Tests that the write error messages' strings are truncated properly.
+ *
+ * @tags: [
+ * assumes_write_concern_unchanged,
+ * ]
+ */
+
+(function() {
+'use strict';
+
+var coll = db.write_error_message_truncation;
+coll.drop();
+
+// Insert 3 documents that we will then reinsert in order to generate DuplicateKey errors
+assert.writeOK(coll.insert(
+ [
+ {_id: 0},
+ {_id: 1},
+ {_id: 2},
+ ],
+ {writeConcern: {w: 'majority'}, ordered: true}));
+
+// Ensure DuplicateKey errors during insert all report their messages
+var res = coll.insert(
+ [
+ {_id: 0},
+ {_id: 1},
+ {_id: 2},
+ ],
+ {writeConcern: {w: 'majority'}, ordered: false});
+
+jsTest.log(res.getRawResponse());
+
+assert.eq(0, res.nInserted);
+
+var writeErrors = res.getWriteErrors();
+assert.eq(3, writeErrors.length);
+assert.neq('', writeErrors[0].errmsg);
+assert.neq('', writeErrors[1].errmsg);
+assert.neq('', writeErrors[2].errmsg);
+})();