summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorJames Wahlin <james@mongodb.com>2018-12-09 16:00:09 -0500
committerJames Wahlin <james@mongodb.com>2018-12-12 15:02:45 -0500
commita34b0ac74038a86f22de1d70c58f2f7c51c1a42a (patch)
tree163a839fe74e0d4e7a59da99249e34277244b38a /jstests
parent056d61676f91f6da0a030347ae4b92255d752d8f (diff)
downloadmongo-a34b0ac74038a86f22de1d70c58f2f7c51c1a42a.tar.gz
SERVER-38461 Limit upsert retry to DuplicateKey violations with matching values
Diffstat (limited to 'jstests')
-rw-r--r--jstests/noPassthrough/upsert_duplicate_key_retry.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/jstests/noPassthrough/upsert_duplicate_key_retry.js b/jstests/noPassthrough/upsert_duplicate_key_retry.js
index c35e490377f..b59b9be3a32 100644
--- a/jstests/noPassthrough/upsert_duplicate_key_retry.js
+++ b/jstests/noPassthrough/upsert_duplicate_key_retry.js
@@ -62,5 +62,26 @@
assert.eq(1, oplogColl.find({"op": "i", "ns": "test.upsert_duplicate_key_retry"}).itcount());
assert.eq(1, oplogColl.find({"op": "u", "ns": "test.upsert_duplicate_key_retry"}).itcount());
+ //
+ // Confirm DuplicateKey error for cases that should not be retried.
+ //
+ assert.commandWorked(testDB.runCommand({drop: collName}));
+ assert.commandWorked(testColl.createIndex({x: 1}, {unique: true}));
+
+ // DuplicateKey error on replacement-style upsert, where the unique index key value to be
+ // written does not match the value of the query predicate.
+ assert.commandWorked(testColl.createIndex({x: 1}, {unique: true}));
+ assert.commandWorked(testColl.insert({_id: 1, 'a': 12345}));
+ assert.commandFailedWithCode(testColl.update({x: 3}, {}, {upsert: true}),
+ ErrorCodes.DuplicateKey);
+
+ // DuplicateKey error on update-style upsert, where the unique index key value to be written
+ // does not match the value of the query predicate.
+ assert.commandWorked(testColl.remove({}));
+ assert.commandWorked(testColl.insert({x: 3}));
+ assert.commandWorked(testColl.insert({x: 4}));
+ assert.commandFailedWithCode(testColl.update({x: 3}, {$inc: {x: 1}}, {upsert: true}),
+ ErrorCodes.DuplicateKey);
+
rst.stopSet();
})();