diff options
author | Josef Ahmad <josef.ahmad@mongodb.com> | 2022-01-18 13:20:00 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-01-18 13:46:47 +0000 |
commit | fd275f66b712e0af181b53575efbe8a87f214a5e (patch) | |
tree | d41c09eab1a4f252a30221e32540f7b06fed08e0 /jstests/noPassthrough/clustered_capped_collection.js | |
parent | a19f0b1c2575b8423c65f56e81d1e077274d0065 (diff) | |
download | mongo-fd275f66b712e0af181b53575efbe8a87f214a5e.tar.gz |
SERVER-61278 Guard capped clustered collections behind enableTestCommands
Diffstat (limited to 'jstests/noPassthrough/clustered_capped_collection.js')
-rw-r--r-- | jstests/noPassthrough/clustered_capped_collection.js | 101 |
1 files changed, 59 insertions, 42 deletions
diff --git a/jstests/noPassthrough/clustered_capped_collection.js b/jstests/noPassthrough/clustered_capped_collection.js index ba34b1d2bff..4c24ceed858 100644 --- a/jstests/noPassthrough/clustered_capped_collection.js +++ b/jstests/noPassthrough/clustered_capped_collection.js @@ -12,17 +12,6 @@ load("jstests/libs/clustered_collections/clustered_collection_util.js"); -const replSet = new ReplSetTest({name: "clustered_capped_collections", nodes: 1}); -replSet.startSet({setParameter: {ttlMonitorSleepSecs: 1}}); -replSet.initiate(); - -if (ClusteredCollectionUtil.areClusteredIndexesEnabled(replSet.getPrimary().getDB("test")) == - false) { - jsTestLog('Skipping test because the clustered indexes feature flag is disabled'); - replSet.stopSet(); - return; -} - // Validate TTL-based deletion on a clustered, capped collection. function testClusteredCappedCollectionWithTTL(db, collName, clusterKeyField) { jsTest.log("Validating TTL operation on capped clustered collection"); @@ -325,37 +314,65 @@ function testClusteredReplicatedTTLDeletion(db, collName) { db.getCollection(collName).drop(); } -const replicatedDB = replSet.getPrimary().getDB('replicated'); -const nonReplicatedDB = replSet.getPrimary().getDB('local'); -const collName = 'clustered_collection'; -const replicatedColl = replicatedDB[collName]; -const nonReplicatedColl = nonReplicatedDB[collName]; - -replicatedColl.drop(); -nonReplicatedColl.drop(); - -testClusteredCappedCollectionWithTTL(replicatedDB, collName, '_id'); -testClusteredTailableCursorCreation(replicatedDB, collName, '_id', true /* isReplicated */); -for (let awaitData of [false, true]) { - testClusteredTailableCursorWithTTL( - replicatedDB, collName, '_id', true /* isReplicated */, awaitData); - testClusteredTailableCursorCappedPositionLostWithTTL( - replicatedDB, collName, '_id', true /* isReplicated */, awaitData); - testClusteredTailableCursorOutOfOrderInsertion( - replicatedDB, collName, '_id', true /* isReplicated */, awaitData); -} -testClusteredReplicatedTTLDeletion(replicatedDB, collName); - -testClusteredCappedCollectionWithTTL(nonReplicatedDB, collName, 'ts'); -testClusteredTailableCursorCreation(nonReplicatedDB, collName, 'ts', false /* isReplicated */); -for (let awaitData of [false, true]) { - testClusteredTailableCursorWithTTL( - nonReplicatedDB, collName, 'ts', false /* isReplicated */, awaitData); - testClusteredTailableCursorCappedPositionLostWithTTL( - nonReplicatedDB, collName, 'ts', false /* isReplicated */, awaitData); - testClusteredTailableCursorOutOfOrderInsertion( - nonReplicatedDB, collName, 'ts', false /* isReplicated */, awaitData); +{ + const replSet = new ReplSetTest({name: "clustered_capped_collections", nodes: 1}); + replSet.startSet({setParameter: {ttlMonitorSleepSecs: 1}}); + replSet.initiate(); + + if (ClusteredCollectionUtil.areClusteredIndexesEnabled(replSet.getPrimary().getDB("test")) == + false) { + jsTestLog('Skipping test because the clustered indexes feature flag is disabled'); + replSet.stopSet(); + return; + } + const replicatedDB = replSet.getPrimary().getDB('replicated'); + const nonReplicatedDB = replSet.getPrimary().getDB('local'); + const collName = 'clustered_collection'; + const replicatedColl = replicatedDB[collName]; + const nonReplicatedColl = nonReplicatedDB[collName]; + + replicatedColl.drop(); + nonReplicatedColl.drop(); + + testClusteredCappedCollectionWithTTL(replicatedDB, collName, '_id'); + testClusteredTailableCursorCreation(replicatedDB, collName, '_id', true /* isReplicated */); + for (let awaitData of [false, true]) { + testClusteredTailableCursorWithTTL( + replicatedDB, collName, '_id', true /* isReplicated */, awaitData); + testClusteredTailableCursorCappedPositionLostWithTTL( + replicatedDB, collName, '_id', true /* isReplicated */, awaitData); + testClusteredTailableCursorOutOfOrderInsertion( + replicatedDB, collName, '_id', true /* isReplicated */, awaitData); + } + testClusteredReplicatedTTLDeletion(replicatedDB, collName); + + testClusteredCappedCollectionWithTTL(nonReplicatedDB, collName, 'ts'); + testClusteredTailableCursorCreation(nonReplicatedDB, collName, 'ts', false /* isReplicated */); + for (let awaitData of [false, true]) { + testClusteredTailableCursorWithTTL( + nonReplicatedDB, collName, 'ts', false /* isReplicated */, awaitData); + testClusteredTailableCursorCappedPositionLostWithTTL( + nonReplicatedDB, collName, 'ts', false /* isReplicated */, awaitData); + testClusteredTailableCursorOutOfOrderInsertion( + nonReplicatedDB, collName, 'ts', false /* isReplicated */, awaitData); + } + + replSet.stopSet(); } -replSet.stopSet(); +// enableTestCommands is required for end users to create a capped clustered collection. +{ + TestData.enableTestCommands = false; + const replSetNoTestCommands = new ReplSetTest({name: "clustered_capped_collections", nodes: 1}); + replSetNoTestCommands.startSet(); + replSetNoTestCommands.initiate(); + + assert.commandFailedWithCode( + replSetNoTestCommands.getPrimary().getDB("test").createCollection( + 'c', + {clusteredIndex: {key: {_id: 1}, unique: true}, capped: true, expireAfterSeconds: 10}), + 6127800); + + replSetNoTestCommands.stopSet(); +} })(); |