diff options
Diffstat (limited to 'jstests/replsets/last_op_visible.js')
-rw-r--r-- | jstests/replsets/last_op_visible.js | 83 |
1 files changed, 41 insertions, 42 deletions
diff --git a/jstests/replsets/last_op_visible.js b/jstests/replsets/last_op_visible.js index 4b8b70a24b4..94a0b32cbf0 100644 --- a/jstests/replsets/last_op_visible.js +++ b/jstests/replsets/last_op_visible.js @@ -8,51 +8,50 @@ load("jstests/replsets/rslib.js"); (function() { - "use strict"; +"use strict"; - var name = 'lastOpVisible'; - var replTest = new ReplSetTest( - {name: name, nodes: 3, nodeOptions: {enableMajorityReadConcern: ''}, waitForKeys: true}); +var name = 'lastOpVisible'; +var replTest = new ReplSetTest( + {name: name, nodes: 3, nodeOptions: {enableMajorityReadConcern: ''}, waitForKeys: true}); - if (!startSetIfSupportsReadMajority(replTest)) { - jsTestLog("Skipping test since storage engine doesn't support majority read concern."); - replTest.stopSet(); - return; - } - replTest.initiate(); - - var primary = replTest.getPrimary(); +if (!startSetIfSupportsReadMajority(replTest)) { + jsTestLog("Skipping test since storage engine doesn't support majority read concern."); + replTest.stopSet(); + return; +} +replTest.initiate(); - // Do an insert without writeConcern. - var res = primary.getDB(name).runCommandWithMetadata({insert: name, documents: [{x: 1}]}, - {"$replData": 1}); - assert.commandWorked(res.commandReply); - var last_op_visible = res.commandReply["$replData"].lastOpVisible; +var primary = replTest.getPrimary(); - // A find should return the same lastVisibleOp. - res = primary.getDB(name).runCommandWithMetadata({find: name, readConcern: {level: "local"}}, +// Do an insert without writeConcern. +var res = primary.getDB(name).runCommandWithMetadata({insert: name, documents: [{x: 1}]}, {"$replData": 1}); - assert.commandWorked(res.commandReply); - assert.eq(last_op_visible, res.commandReply["$replData"].lastOpVisible); - - // A majority readConcern with afterOpTime: lastOpVisible should also return the same - // lastVisibleOp. - res = primary.getDB(name).runCommandWithMetadata( - {find: name, readConcern: {level: "majority", afterOpTime: last_op_visible}}, - {"$replData": 1}); - assert.commandWorked(res.commandReply); - assert.eq(last_op_visible, res.commandReply["$replData"].lastOpVisible); - - // Do an insert without writeConcern. - res = primary.getDB(name).runCommandWithMetadata( - {insert: name, documents: [{x: 1}], writeConcern: {w: "majority"}}, {"$replData": 1}); - assert.commandWorked(res.commandReply); - last_op_visible = res.commandReply["$replData"].lastOpVisible; - - // A majority readConcern should return the same lastVisibleOp. - res = primary.getDB(name).runCommandWithMetadata({find: name, readConcern: {level: "majority"}}, - {"$replData": 1}); - assert.commandWorked(res.commandReply); - assert.eq(last_op_visible, res.commandReply["$replData"].lastOpVisible); - replTest.stopSet(); +assert.commandWorked(res.commandReply); +var last_op_visible = res.commandReply["$replData"].lastOpVisible; + +// A find should return the same lastVisibleOp. +res = primary.getDB(name).runCommandWithMetadata({find: name, readConcern: {level: "local"}}, + {"$replData": 1}); +assert.commandWorked(res.commandReply); +assert.eq(last_op_visible, res.commandReply["$replData"].lastOpVisible); + +// A majority readConcern with afterOpTime: lastOpVisible should also return the same +// lastVisibleOp. +res = primary.getDB(name).runCommandWithMetadata( + {find: name, readConcern: {level: "majority", afterOpTime: last_op_visible}}, {"$replData": 1}); +assert.commandWorked(res.commandReply); +assert.eq(last_op_visible, res.commandReply["$replData"].lastOpVisible); + +// Do an insert without writeConcern. +res = primary.getDB(name).runCommandWithMetadata( + {insert: name, documents: [{x: 1}], writeConcern: {w: "majority"}}, {"$replData": 1}); +assert.commandWorked(res.commandReply); +last_op_visible = res.commandReply["$replData"].lastOpVisible; + +// A majority readConcern should return the same lastVisibleOp. +res = primary.getDB(name).runCommandWithMetadata({find: name, readConcern: {level: "majority"}}, + {"$replData": 1}); +assert.commandWorked(res.commandReply); +assert.eq(last_op_visible, res.commandReply["$replData"].lastOpVisible); +replTest.stopSet(); }()); |