summaryrefslogtreecommitdiff
path: root/jstests/replsets/temp_namespace.js
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2014-10-12 12:25:39 -0400
committerEliot Horowitz <eliot@10gen.com>2014-10-12 12:55:42 -0400
commitb186710fdc197117c7bbc2df2492868e1ff5aa92 (patch)
tree4e1b36e70747e14ad99b0398b7dc6b05fca321b9 /jstests/replsets/temp_namespace.js
parentfc00132dd762f1ba12dd462e780ffd4e232c96e4 (diff)
downloadmongo-b186710fdc197117c7bbc2df2492868e1ff5aa92.tar.gz
SERVER-13635: make some replset tests generic
Diffstat (limited to 'jstests/replsets/temp_namespace.js')
-rw-r--r--jstests/replsets/temp_namespace.js46
1 files changed, 31 insertions, 15 deletions
diff --git a/jstests/replsets/temp_namespace.js b/jstests/replsets/temp_namespace.js
index 90d72400518..a7816bd61a4 100644
--- a/jstests/replsets/temp_namespace.js
+++ b/jstests/replsets/temp_namespace.js
@@ -33,13 +33,29 @@ masterDB.runCommand({create: 'keep3'});
assert.writeOK(masterDB.keep4.insert({}, { writeConcern: { w: 2 }}));
// make sure they exist on primary and secondary
-assert.eq(masterDB.system.namespaces.count({name: /temp\d$/}) , 2); // collections
-assert.eq(masterDB.system.namespaces.count({name: /temp\d\.\$.*$/}) , 4); // indexes (2 _id + 2 x)
-assert.eq(masterDB.system.namespaces.count({name: /keep\d$/}) , 4);
+function countCollection( mydb, nameFilter ) {
+ return mydb.runCommand( "listCollections",
+ { filter : { name : nameFilter } } ).collections.length;
+}
+
+function coundIndexesFor( mydb, nameFilter ) {
+ var arr = mydb.runCommand( "listCollections",
+ { filter : { name : nameFilter } } ).collections;
+ var total = 0;
+ for ( var i = 0; i < arr.length; i++ ) {
+ var coll = arr[i];
+ total += mydb.getCollection( coll.name ).getIndexes().length;
+ }
+ return total;
+}
+
+assert.eq(countCollection(masterDB,/temp\d$/), 2); // collections
+assert.eq(coundIndexesFor(masterDB,/temp\d$/), 4); // indexes (2 _id + 2 x)
+assert.eq(countCollection(masterDB,/keep\d$/), 4);
-assert.eq(secondDB.system.namespaces.count({name: /temp\d$/}) , 2); // collections
-assert.eq(secondDB.system.namespaces.count({name: /temp\d\.\$.*$/}) , 4); // indexes (2 _id + 2 x)
-assert.eq(secondDB.system.namespaces.count({name: /keep\d$/}) , 4);
+assert.eq(countCollection(secondDB,/temp\d$/), 2); // collections
+assert.eq(coundIndexesFor(secondDB,/temp\d$/), 4); // indexes (2 _id + 2 x)
+assert.eq(countCollection(secondDB,/keep\d$/), 4);
// restart secondary and reconnect
replTest.restart(secondId, {}, /*wait=*/true);
@@ -56,9 +72,9 @@ assert.soon(function () {
}, "took more than a minute for the secondary to become secondary again", 60*1000);
// make sure restarting secondary didn't drop collections
-assert.eq(secondDB.system.namespaces.count({name: /temp\d$/}) , 2); // collections
-assert.eq(secondDB.system.namespaces.count({name: /temp\d\.\$.*$/}) , 4); // indexes (2 _id + 2 x)
-assert.eq(secondDB.system.namespaces.count({name: /keep\d$/}) , 4);
+assert.eq(countCollection(secondDB,/temp\d$/), 2); // collections
+assert.eq(coundIndexesFor(secondDB,/temp\d$/), 4); // indexes (2 _id + 2 x)
+assert.eq(countCollection(secondDB,/keep\d$/), 4);
// step down primary and make sure former secondary (now primary) drops collections
try {
@@ -73,14 +89,14 @@ assert.soon(function() {
return secondDB.isMaster().ismaster;
}, '', 75*1000); // must wait for secondary to be willing to promote self
-assert.eq(secondDB.system.namespaces.count({name: /temp\d$/}) , 0); // collections
-assert.eq(secondDB.system.namespaces.count({name: /temp\d\.\$.*$/}) , 0); //indexes
-assert.eq(secondDB.system.namespaces.count({name: /keep\d$/}) , 4);
+assert.eq(countCollection(secondDB,/temp\d$/), 0); // collections
+assert.eq(coundIndexesFor(secondDB,/temp\d$/), 0); // indexes (2 _id + 2 x)
+assert.eq(countCollection(secondDB,/keep\d$/), 4);
// check that former primary dropped collections
replTest.awaitReplication()
-assert.eq(masterDB.system.namespaces.count({name: /temp\d$/}) , 0); // collections
-assert.eq(masterDB.system.namespaces.count({name: /temp\d\.\$.*$/}) , 0); //indexes
-assert.eq(masterDB.system.namespaces.count({name: /keep\d$/}) , 4);
+assert.eq(countCollection(masterDB,/temp\d$/), 0); // collections
+assert.eq(coundIndexesFor(masterDB,/temp\d$/), 0); // indexes (2 _id + 2 x)
+assert.eq(countCollection(masterDB,/keep\d$/), 4);
replTest.stopSet();