summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/change_streams_require_majority_read_concern.js
diff options
context:
space:
mode:
authorclang-format-7.0.1 <adam.martin@10gen.com>2019-07-26 18:20:35 -0400
committerADAM David Alan Martin <adam.martin@10gen.com>2019-07-27 11:02:23 -0400
commit134a4083953270e8a11430395357fb70a29047ad (patch)
treedd428e1230e31d92b20b393dfdc17ffe7fa79cb6 /jstests/noPassthrough/change_streams_require_majority_read_concern.js
parent1e46b5049003f427047e723ea5fab15b5a9253ca (diff)
downloadmongo-134a4083953270e8a11430395357fb70a29047ad.tar.gz
SERVER-41772 Apply clang-format 7.0.1 to the codebase
Diffstat (limited to 'jstests/noPassthrough/change_streams_require_majority_read_concern.js')
-rw-r--r--jstests/noPassthrough/change_streams_require_majority_read_concern.js157
1 files changed, 78 insertions, 79 deletions
diff --git a/jstests/noPassthrough/change_streams_require_majority_read_concern.js b/jstests/noPassthrough/change_streams_require_majority_read_concern.js
index 8481ba586f1..6fdc4c2ee37 100644
--- a/jstests/noPassthrough/change_streams_require_majority_read_concern.js
+++ b/jstests/noPassthrough/change_streams_require_majority_read_concern.js
@@ -1,97 +1,96 @@
// Tests that the $changeStream requires read concern majority.
// @tags: [uses_change_streams]
(function() {
- "use strict";
+"use strict";
- load("jstests/replsets/rslib.js"); // For startSetIfSupportsReadMajority.
- load("jstests/libs/change_stream_util.js"); // For ChangeStreamTest.
- load("jstests/libs/namespace_utils.js"); // For getCollectionNameFromFullNamespace.
- load("jstests/libs/write_concern_util.js"); // For stopReplicationOnSecondaries.
+load("jstests/replsets/rslib.js"); // For startSetIfSupportsReadMajority.
+load("jstests/libs/change_stream_util.js"); // For ChangeStreamTest.
+load("jstests/libs/namespace_utils.js"); // For getCollectionNameFromFullNamespace.
+load("jstests/libs/write_concern_util.js"); // For stopReplicationOnSecondaries.
- const rst = new ReplSetTest({nodes: 2, nodeOptions: {enableMajorityReadConcern: ""}});
+const rst = new ReplSetTest({nodes: 2, nodeOptions: {enableMajorityReadConcern: ""}});
- // Skip this test if running with --nojournal and WiredTiger.
- if (jsTest.options().noJournal &&
- (!jsTest.options().storageEngine || jsTest.options().storageEngine === "wiredTiger")) {
- print("Skipping test because running WiredTiger without journaling isn't a valid" +
- " replica set configuration");
- return;
- }
+// Skip this test if running with --nojournal and WiredTiger.
+if (jsTest.options().noJournal &&
+ (!jsTest.options().storageEngine || jsTest.options().storageEngine === "wiredTiger")) {
+ print("Skipping test because running WiredTiger without journaling isn't a valid" +
+ " replica set configuration");
+ return;
+}
- if (!startSetIfSupportsReadMajority(rst)) {
- jsTestLog("Skipping test since storage engine doesn't support majority read concern.");
- rst.stopSet();
- return;
- }
+if (!startSetIfSupportsReadMajority(rst)) {
+ jsTestLog("Skipping test since storage engine doesn't support majority read concern.");
+ rst.stopSet();
+ return;
+}
- rst.initiate();
+rst.initiate();
- const name = "change_stream_require_majority_read_concern";
- const db = rst.getPrimary().getDB(name);
+const name = "change_stream_require_majority_read_concern";
+const db = rst.getPrimary().getDB(name);
- // Use ChangeStreamTest to verify that the pipeline returns expected results.
- const cst = new ChangeStreamTest(db);
+// Use ChangeStreamTest to verify that the pipeline returns expected results.
+const cst = new ChangeStreamTest(db);
- // Attempts to get a document from the cursor with awaitData disabled, and asserts if a
- // document is present.
- function assertNextBatchIsEmpty(cursor) {
- assert.commandWorked(db.adminCommand(
- {configureFailPoint: "disableAwaitDataForGetMoreCmd", mode: "alwaysOn"}));
- let res = assert.commandWorked(db.runCommand({
- getMore: cursor.id,
- collection: getCollectionNameFromFullNamespace(cursor.ns),
- batchSize: 1
- }));
- assert.eq(res.cursor.nextBatch.length, 0);
- assert.commandWorked(
- db.adminCommand({configureFailPoint: "disableAwaitDataForGetMoreCmd", mode: "off"}));
- }
+// Attempts to get a document from the cursor with awaitData disabled, and asserts if a
+// document is present.
+function assertNextBatchIsEmpty(cursor) {
+ assert.commandWorked(
+ db.adminCommand({configureFailPoint: "disableAwaitDataForGetMoreCmd", mode: "alwaysOn"}));
+ let res = assert.commandWorked(db.runCommand({
+ getMore: cursor.id,
+ collection: getCollectionNameFromFullNamespace(cursor.ns),
+ batchSize: 1
+ }));
+ assert.eq(res.cursor.nextBatch.length, 0);
+ assert.commandWorked(
+ db.adminCommand({configureFailPoint: "disableAwaitDataForGetMoreCmd", mode: "off"}));
+}
- // Test read concerns other than "majority" are not supported.
- const primaryColl = db.foo;
- assert.writeOK(primaryColl.insert({_id: 1}, {writeConcern: {w: "majority"}}));
- let res = primaryColl.runCommand({
- aggregate: primaryColl.getName(),
- pipeline: [{$changeStream: {}}],
- cursor: {},
- readConcern: {level: "local"},
- });
- assert.commandFailedWithCode(res, ErrorCodes.InvalidOptions);
- res = primaryColl.runCommand({
- aggregate: primaryColl.getName(),
- pipeline: [{$changeStream: {}}],
- cursor: {},
- readConcern: {level: "linearizable"},
- });
- assert.commandFailedWithCode(res, ErrorCodes.InvalidOptions);
+// Test read concerns other than "majority" are not supported.
+const primaryColl = db.foo;
+assert.writeOK(primaryColl.insert({_id: 1}, {writeConcern: {w: "majority"}}));
+let res = primaryColl.runCommand({
+ aggregate: primaryColl.getName(),
+ pipeline: [{$changeStream: {}}],
+ cursor: {},
+ readConcern: {level: "local"},
+});
+assert.commandFailedWithCode(res, ErrorCodes.InvalidOptions);
+res = primaryColl.runCommand({
+ aggregate: primaryColl.getName(),
+ pipeline: [{$changeStream: {}}],
+ cursor: {},
+ readConcern: {level: "linearizable"},
+});
+assert.commandFailedWithCode(res, ErrorCodes.InvalidOptions);
- // Test that explicit read concern "majority" works.
- res = primaryColl.runCommand({
- aggregate: primaryColl.getName(),
- pipeline: [{$changeStream: {}}],
- cursor: {},
- readConcern: {level: "majority"},
- });
- assert.commandWorked(res);
+// Test that explicit read concern "majority" works.
+res = primaryColl.runCommand({
+ aggregate: primaryColl.getName(),
+ pipeline: [{$changeStream: {}}],
+ cursor: {},
+ readConcern: {level: "majority"},
+});
+assert.commandWorked(res);
- // Test not specifying readConcern defaults to "majority" read concern.
- stopReplicationOnSecondaries(rst);
- // Verify that the document just inserted cannot be returned.
- let cursor =
- cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: primaryColl});
- assert.eq(cursor.firstBatch.length, 0);
+// Test not specifying readConcern defaults to "majority" read concern.
+stopReplicationOnSecondaries(rst);
+// Verify that the document just inserted cannot be returned.
+let cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: primaryColl});
+assert.eq(cursor.firstBatch.length, 0);
- // Insert a document on the primary only.
- assert.writeOK(primaryColl.insert({_id: 2}, {writeConcern: {w: 1}}));
- assertNextBatchIsEmpty(cursor);
+// Insert a document on the primary only.
+assert.writeOK(primaryColl.insert({_id: 2}, {writeConcern: {w: 1}}));
+assertNextBatchIsEmpty(cursor);
- // Restart data replicaiton and wait until the new write becomes visible.
- restartReplicationOnSecondaries(rst);
- rst.awaitLastOpCommitted();
+// Restart data replicaiton and wait until the new write becomes visible.
+restartReplicationOnSecondaries(rst);
+rst.awaitLastOpCommitted();
- // Verify that the expected doc is returned because it has been committed.
- let doc = cst.getOneChange(cursor);
- assert.docEq(doc.operationType, "insert");
- assert.docEq(doc.fullDocument, {_id: 2});
- rst.stopSet();
+// Verify that the expected doc is returned because it has been committed.
+let doc = cst.getOneChange(cursor);
+assert.docEq(doc.operationType, "insert");
+assert.docEq(doc.fullDocument, {_id: 2});
+rst.stopSet();
}());