diff options
author | Geert Bosch <geert@mongodb.com> | 2016-05-24 18:25:51 -0400 |
---|---|---|
committer | Geert Bosch <geert@mongodb.com> | 2016-06-03 21:54:34 -0400 |
commit | e533634d86aae9385d9bdd94e15d992c4c8de622 (patch) | |
tree | 5332d6b28e6fef68e7ad27dda650a09b3924aba3 /jstests | |
parent | 94b2682abc46a7739e52bba12b3ecdae16b5f8e8 (diff) | |
download | mongo-e533634d86aae9385d9bdd94e15d992c4c8de622.tar.gz |
SERVER-23326 Commit applyOps as single WUOW where possibler3.3.7
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/core/apply_ops1.js | 11 | ||||
-rw-r--r-- | jstests/core/apply_ops2.js | 3 | ||||
-rw-r--r-- | jstests/core/apply_ops_atomicity.js | 27 | ||||
-rw-r--r-- | jstests/core/bypass_doc_validation.js | 4 | ||||
-rw-r--r-- | jstests/noPassthroughWithMongod/apply_ops_errors.js | 4 |
5 files changed, 40 insertions, 9 deletions
diff --git a/jstests/core/apply_ops1.js b/jstests/core/apply_ops1.js index 96840f125e9..34a38185c01 100644 --- a/jstests/core/apply_ops1.js +++ b/jstests/core/apply_ops1.js @@ -39,20 +39,23 @@ assert.commandWorked(db.adminCommand({applyOps: [{op: 'n', ns: ''}]}), 'applyOps should work on no op operation with empty "ns" field value'); + // Missing dbname in 'ns' field. + assert.commandFailed(db.adminCommand({applyOps: [{op: 'd', ns: t.getName(), o: {_id: 1}}]})); + // Missing 'o' field value in an operation of type 'c' (command). - assert.commandFailed(db.adminCommand({applyOps: [{op: 'c', ns: 'foo'}]}), + assert.commandFailed(db.adminCommand({applyOps: [{op: 'c', ns: t.getFullName()}]}), 'applyOps should fail on command operation without "o" field'); // Non-object 'o' field value in an operation of type 'c' (command). - assert.commandFailed(db.adminCommand({applyOps: [{op: 'c', ns: 'foo', o: 'bar'}]}), + assert.commandFailed(db.adminCommand({applyOps: [{op: 'c', ns: t.getFullName(), o: 'bar'}]}), 'applyOps should fail on command operation with non-object "o" field'); // Empty object 'o' field value in an operation of type 'c' (command). - assert.commandFailed(db.adminCommand({applyOps: [{op: 'c', ns: 'foo', o: {}}]}), + assert.commandFailed(db.adminCommand({applyOps: [{op: 'c', ns: t.getFullName(), o: {}}]}), 'applyOps should fail on command operation with empty object "o" field'); // Unknown key in 'o' field value in an operation of type 'c' (command). - assert.commandFailed(db.adminCommand({applyOps: [{op: 'c', ns: 'foo', o: {a: 1}}]}), + assert.commandFailed(db.adminCommand({applyOps: [{op: 'c', ns: t.getFullName(), o: {a: 1}}]}), 'applyOps should fail on command operation on unknown key in "o" field'); // Empty 'ns' field value in operation type other than 'n'. diff --git a/jstests/core/apply_ops2.js b/jstests/core/apply_ops2.js index bf804214846..4e99cee37ff 100644 --- a/jstests/core/apply_ops2.js +++ b/jstests/core/apply_ops2.js @@ -33,7 +33,8 @@ res = db.runCommand({ alwaysUpsert: false }); -assert.eq(true, res.results[0], "upsert = false, existing doc update failed"); +// Because the CRUD apply-ops are atomic, all results are false, even the first one. +assert.eq(false, res.results[0], "upsert = false, existing doc update failed"); assert.eq(false, res.results[1], "upsert = false, nonexisting doc upserted"); assert.eq(2, t.find().count(), "2 docs expected after upsert failure"); diff --git a/jstests/core/apply_ops_atomicity.js b/jstests/core/apply_ops_atomicity.js new file mode 100644 index 00000000000..2d093555200 --- /dev/null +++ b/jstests/core/apply_ops_atomicity.js @@ -0,0 +1,27 @@ +// SERVER-23326: Make applyOps atomic for CRUD operations +(function() { + 'use strict'; + + var t = db.applyOps; + t.drop(); + assert.writeOK(t.insert({_id: 1})); + + // Operations including commands should not be atomic, so the insert will succeed. + assert.commandFailed(db.adminCommand({ + applyOps: [ + {op: 'i', ns: t.getFullName(), o: {_id: ObjectId(), x: 1}}, + {op: 'c', ns: "invalid", o: {create: "t"}}, + ] + })); + assert.eq(t.count({x: 1}), 1); + + // Operations only including CRUD commands should be atomic, so the next insert will fail. + var tooLong = Array(2000).join("hello"); + assert.commandFailed(db.adminCommand({ + applyOps: [ + {op: 'i', ns: t.getFullName(), o: {_id: ObjectId(), x: 1}}, + {op: 'i', ns: t.getFullName(), o: {_id: tooLong, x: 1}}, + ] + })); + assert.eq(t.count({x: 1}), 1); +})(); diff --git a/jstests/core/bypass_doc_validation.js b/jstests/core/bypass_doc_validation.js index 79a2eb7d4a2..d9bca81ab6d 100644 --- a/jstests/core/bypass_doc_validation.js +++ b/jstests/core/bypass_doc_validation.js @@ -19,9 +19,9 @@ // Test applyOps with a simple insert if not on mongos. if (!db.runCommand({isdbgrid: 1}).isdbgrid) { var op = [{ts: Timestamp(0, 0), h: 1, v: 2, op: 'i', ns: coll.getFullName(), o: {_id: 9}}]; - // SERVER-21345: applyOps is returning UnknownError instead of DocumentValidationFailure assert.commandFailedWithCode( - myDb.runCommand({applyOps: op, bypassDocumentValidation: false}), 8); + myDb.runCommand({applyOps: op, bypassDocumentValidation: false}), + ErrorCodes.DocumentValidationFailure); assert.eq(0, coll.count({_id: 9})); assert.commandWorked(myDb.runCommand({applyOps: op, bypassDocumentValidation: true})); assert.eq(1, coll.count({_id: 9})); diff --git a/jstests/noPassthroughWithMongod/apply_ops_errors.js b/jstests/noPassthroughWithMongod/apply_ops_errors.js index d2f584af787..9441d006e43 100644 --- a/jstests/noPassthroughWithMongod/apply_ops_errors.js +++ b/jstests/noPassthroughWithMongod/apply_ops_errors.js @@ -52,6 +52,6 @@ assert.eq(2, res.applied); assert(res.code); assert(res.errmsg); - assert.eq([true, false], res.results); + assert.eq([false, false], res.results); assert.eq(0, res.ok); -})();
\ No newline at end of file +})(); |