summaryrefslogtreecommitdiff
path: root/jstests/replsets/apply_ops_wc.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/replsets/apply_ops_wc.js')
-rw-r--r--jstests/replsets/apply_ops_wc.js79
1 files changed, 27 insertions, 52 deletions
diff --git a/jstests/replsets/apply_ops_wc.js b/jstests/replsets/apply_ops_wc.js
index cb50b9b9070..0b8a49e19bd 100644
--- a/jstests/replsets/apply_ops_wc.js
+++ b/jstests/replsets/apply_ops_wc.js
@@ -12,7 +12,7 @@
(function() {
"use strict";
var nodeCount = 3;
- var replTest = new ReplSetTest({ name: 'applyOpsWCSet', nodes: nodeCount});
+ var replTest = new ReplSetTest({name: 'applyOpsWCSet', nodes: nodeCount});
replTest.startSet();
var cfg = replTest.getReplSetConfig();
cfg.settings = {};
@@ -34,32 +34,13 @@
dropTestCollection();
// Set up the applyOps command.
- var applyOpsReq = { applyOps: [
- {
- op: "i",
- ns: coll.getFullName(),
- o: {
- _id: 2,
- x: "b"
- }
- },
- {
- op: "i",
- ns: coll.getFullName(),
- o: {
- _id: 3,
- x: "c"
- }
- },
- {
- op: "i",
- ns: coll.getFullName(),
- o: {
- _id: 4,
- x: "d"
- }
- },
- ]};
+ var applyOpsReq = {
+ applyOps: [
+ {op: "i", ns: coll.getFullName(), o: {_id: 2, x: "b"}},
+ {op: "i", ns: coll.getFullName(), o: {_id: 3, x: "c"}},
+ {op: "i", ns: coll.getFullName(), o: {_id: 4, x: "d"}},
+ ]
+ };
function assertApplyOpsCommandWorked(res) {
assert.eq(3, res.applied);
@@ -73,10 +54,7 @@
assert(res.writeConcernError.errmsg);
}
- var invalidWriteConcerns = [
- { w: 'invalid' },
- { w: nodeCount + 1 }
- ];
+ var invalidWriteConcerns = [{w: 'invalid'}, {w: nodeCount + 1}];
function testInvalidWriteConcern(wc) {
jsTest.log("Testing invalid write concern " + tojson(wc));
@@ -85,28 +63,24 @@
var res = coll.runCommand(applyOpsReq);
assertApplyOpsCommandWorked(res);
assertWriteConcernError(res);
-
}
// Verify that invalid write concerns yield an error.
- coll.insert({ _id: 1, x: "a" });
+ coll.insert({_id: 1, x: "a"});
invalidWriteConcerns.forEach(testInvalidWriteConcern);
var secondaries = replTest.getSecondaries();
- var majorityWriteConcerns = [
- { w: 2, wtimeout: 30000 },
- { w: 'majority', wtimeout: 30000 },
- ];
+ var majorityWriteConcerns = [{w: 2, wtimeout: 30000}, {w: 'majority', wtimeout: 30000}, ];
function testMajorityWriteConcerns(wc) {
jsTest.log("Testing " + tojson(wc));
// Reset secondaries to ensure they can replicate.
- secondaries[0].getDB('admin').runCommand({ configureFailPoint: 'rsSyncApplyStop',
- mode: 'off' });
- secondaries[1].getDB('admin').runCommand({ configureFailPoint: 'rsSyncApplyStop',
- mode: 'off' });
+ secondaries[0].getDB('admin').runCommand(
+ {configureFailPoint: 'rsSyncApplyStop', mode: 'off'});
+ secondaries[1].getDB('admin').runCommand(
+ {configureFailPoint: 'rsSyncApplyStop', mode: 'off'});
// Set the writeConcern of the applyOps command.
applyOpsReq.writeConcern = wc;
@@ -114,36 +88,37 @@
dropTestCollection();
// applyOps with a full replica set should succeed.
- coll.insert({ _id: 1, x: "a" });
+ coll.insert({_id: 1, x: "a"});
var res = db.runCommand(applyOpsReq);
assertApplyOpsCommandWorked(res);
- assert(!res.writeConcernError, 'applyOps on a full replicaset had writeConcern error ' +
- tojson(res.writeConcernError));
+ assert(!res.writeConcernError,
+ 'applyOps on a full replicaset had writeConcern error ' +
+ tojson(res.writeConcernError));
dropTestCollection();
// Stop replication at one secondary.
- secondaries[0].getDB('admin').runCommand({ configureFailPoint: 'rsSyncApplyStop',
- mode: 'alwaysOn' });
+ secondaries[0].getDB('admin').runCommand(
+ {configureFailPoint: 'rsSyncApplyStop', mode: 'alwaysOn'});
// applyOps should succeed with only 1 node not replicating.
- coll.insert({ _id: 1, x: "a" });
+ coll.insert({_id: 1, x: "a"});
res = db.runCommand(applyOpsReq);
assertApplyOpsCommandWorked(res);
assert(!res.writeConcernError,
- 'applyOps on a replicaset with 2 working nodes had writeConcern error ' +
- tojson(res.writeConcernError));
+ 'applyOps on a replicaset with 2 working nodes had writeConcern error ' +
+ tojson(res.writeConcernError));
dropTestCollection();
// Stop replication at a second secondary.
- secondaries[1].getDB('admin').runCommand({ configureFailPoint: 'rsSyncApplyStop',
- mode: 'alwaysOn' });
+ secondaries[1].getDB('admin').runCommand(
+ {configureFailPoint: 'rsSyncApplyStop', mode: 'alwaysOn'});
// applyOps should fail after two nodes have stopped replicating.
- coll.insert({ _id: 1, x: "a" });
+ coll.insert({_id: 1, x: "a"});
applyOpsReq.writeConcern.wtimeout = 5000;
res = db.runCommand(applyOpsReq);