diff options
author | Eliot Horowitz <eliot@10gen.com> | 2014-10-12 12:25:39 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2014-10-12 12:55:42 -0400 |
commit | b186710fdc197117c7bbc2df2492868e1ff5aa92 (patch) | |
tree | 4e1b36e70747e14ad99b0398b7dc6b05fca321b9 /jstests | |
parent | fc00132dd762f1ba12dd462e780ffd4e232c96e4 (diff) | |
download | mongo-b186710fdc197117c7bbc2df2492868e1ff5aa92.tar.gz |
SERVER-13635: make some replset tests generic
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/replsets/rollback2.js | 5 | ||||
-rw-r--r-- | jstests/replsets/temp_namespace.js | 46 |
2 files changed, 33 insertions, 18 deletions
diff --git a/jstests/replsets/rollback2.js b/jstests/replsets/rollback2.js index d80e7b7349e..e187af18bc1 100644 --- a/jstests/replsets/rollback2.js +++ b/jstests/replsets/rollback2.js @@ -52,8 +52,8 @@ function wait(f) { function dbs_match(a, b) { print("dbs_match"); - var ac = a.system.namespaces.find().sort({name:1}).toArray(); - var bc = b.system.namespaces.find().sort({name:1}).toArray(); + var ac = a.getCollectionNames(); + var bc = b.getCollectionNames(); if (!friendlyEqual(ac, bc)) { print("dbs_match: namespaces don't match"); print("\n\n"); @@ -183,7 +183,6 @@ doTest = function (signal) { return status.members[1].state == 2; }); - A.runCommand({ replSetTest: 1, blind: true }); reconnect(a, b); 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(); |