summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2022-02-24 21:12:09 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-25 02:39:37 +0000
commit14dfd0e4d652d7dff7e21f4eaa36e33e67d5ebff (patch)
tree803ce94653f59e06decf1b11d42bcbd72b5b5d57
parentdc08f5388a525a721a002e3a171ef627584f25eb (diff)
downloadmongo-14dfd0e4d652d7dff7e21f4eaa36e33e67d5ebff.tar.gz
SERVER-62006 add read concern js test for listCatalog aggregation stage
-rw-r--r--jstests/noPassthrough/list_catalog_read_concern.js93
1 files changed, 93 insertions, 0 deletions
diff --git a/jstests/noPassthrough/list_catalog_read_concern.js b/jstests/noPassthrough/list_catalog_read_concern.js
new file mode 100644
index 00000000000..2b1cb6c4647
--- /dev/null
+++ b/jstests/noPassthrough/list_catalog_read_concern.js
@@ -0,0 +1,93 @@
+/**
+ * Tests listCatalog aggregation stage with local and majority read concerns.
+ * @tags: [
+ * requires_replication,
+ * ]
+ */
+(function() {
+'use strict';
+
+load("jstests/libs/fail_point_util.js"); // For configureFailPoint
+
+const rst = new ReplSetTest({nodes: 3});
+rst.startSet();
+rst.initiate();
+
+const primary = rst.getPrimary();
+const documentSourceListCatalogEnabled =
+ assert
+ .commandWorked(
+ primary.adminCommand({getParameter: 1, featureFlagDocumentSourceListCatalog: 1}))
+ .featureFlagDocumentSourceListCatalog.value;
+
+if (!documentSourceListCatalogEnabled) {
+ jsTestLog('Skipping test because the $listCatalog aggregation stage feature flag is disabled.');
+ rst.stopSet();
+ return;
+}
+
+const testDB = primary.getDB('test');
+const coll = testDB.getCollection('t');
+assert.commandWorked(coll.insert({_id: 0}));
+const view = testDB.getCollection('view1');
+assert.commandWorked(testDB.createView(view.getName(), coll.getName(), []));
+rst.awaitReplication();
+
+const secondaries = rst.getSecondaries();
+assert.eq(2, secondaries.length);
+
+let failpoints = [];
+try {
+ failpoints.push(configureFailPoint(secondaries[0], 'rsSyncApplyStop'));
+ failpoints.push(configureFailPoint(secondaries[1], 'rsSyncApplyStop'));
+
+ const collOnPrimaryOnly = testDB.getCollection('w');
+ assert.commandWorked(collOnPrimaryOnly.insert({_id: 1}, {writeConcern: {w: 1}}));
+
+ const viewOnPrimaryOnly = testDB.getCollection('view2');
+ assert.commandWorked(
+ testDB.createView(viewOnPrimaryOnly.getName(), coll.getName(), [], {writeConcern: {w: 1}}));
+
+ const adminDB = testDB.getSiblingDB('admin');
+ const resultLocal = adminDB
+ .aggregate([{$listCatalog: {}}, {$match: {db: testDB.getName()}}],
+ {readConcern: {level: 'local'}})
+ .toArray();
+ const resultMajority = adminDB
+ .aggregate([{$listCatalog: {}}, {$match: {db: testDB.getName()}}],
+ {readConcern: {level: 'majority'}})
+ .toArray();
+
+ jsTestLog('$listCatalog result (local read concern): ' + tojson(resultLocal));
+ jsTestLog('$listCatalog result (majority read concern): ' + tojson(resultMajority));
+
+ const catalogEntriesLocal = Object.assign({}, ...resultLocal.map(doc => ({[doc.ns]: doc})));
+ const catalogEntriesMajority =
+ Object.assign({}, ...resultMajority.map(doc => ({[doc.ns]: doc})));
+ jsTestLog('Catalog entries keyed by namespace (local read concern): ' +
+ tojson(catalogEntriesLocal));
+ jsTestLog('Catalog entries keyed by namespace (majority read concern): ' +
+ tojson(catalogEntriesMajority));
+
+ // $listCatalog result should have all the collections and views we have created.
+ assert.hasFields(catalogEntriesLocal, [
+ coll.getFullName(),
+ view.getFullName(),
+ collOnPrimaryOnly.getFullName(),
+ viewOnPrimaryOnly.getFullName()
+ ]);
+
+ // $listCatalog result should not contain the namespaces not replicated to the secondaries.
+ assert.hasFields(catalogEntriesMajority, [coll.getFullName(), view.getFullName()]);
+ assert(!catalogEntriesMajority.hasOwnProperty(collOnPrimaryOnly.getFullName()),
+ tojson(catalogEntriesMajority));
+ assert(!catalogEntriesMajority.hasOwnProperty(viewOnPrimaryOnly.getFullName()),
+ tojson(catalogEntriesMajority));
+} finally {
+ for (const fp of failpoints) {
+ fp.off();
+ }
+}
+
+rst.stopSet();
+})();