Skip to content

Commit f18c1a1

Browse files
committed
SERVER-16580 Remove deprecated system collection references in JS tests
1 parent 81109be commit f18c1a1

File tree

12 files changed

+59
-42
lines changed

12 files changed

+59
-42
lines changed

jstests/aggregation/bugs/server3253.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ function collectionExists(coll) {
1515
}
1616

1717
function getOutputIndexes() {
18-
return db.system.indexes.find({ns: output.getFullName()}).sort({"key":1}).toArray();
18+
return output.getIndexes().sort(function(a, b) {
19+
if (a.name < b.name) { return -1; }
20+
else { return 1; }
21+
});
1922
}
2023

2124
function test(input, pipeline, expected) {
@@ -26,10 +29,19 @@ function test(input, pipeline, expected) {
2629

2730
assert.eq(cursor.itcount(), 0); // empty cursor returned
2831
assert.eq(output.find().toArray(), expected); // correct results
29-
assert.eq(getOutputIndexes(), indexes); // number of indexes maintained
32+
var outputIndexes = getOutputIndexes();
33+
assert.eq(outputIndexes.length, indexes.length); // number of indexes maintained
34+
for (var i = 0; i < outputIndexes.length; i++) {
35+
assert.docEq(outputIndexes[i], indexes[i]);
36+
}
37+
3038
assert(collectionExists(output));
3139
}
3240

41+
function listCollections(name) {
42+
var collectionInfosCursor = db.runCommand("listCollections", {filter: { name: name}});
43+
return new DBCommandCursor(db.getMongo(), collectionInfosCursor).toArray();
44+
}
3345

3446
input.insert({_id:1});
3547
input.insert({_id:2});
@@ -39,7 +51,7 @@ input.insert({_id:3});
3951
output.insert({_id:1});
4052

4153
// ensure there are no tmp agg_out collections before we begin
42-
assert.eq([], db.system.namespaces.find({name: /tmp\.agg_out/}).toArray());
54+
assert.eq([], listCollections(/tmp\.agg_out/));
4355

4456
// basic test
4557
test(input,
@@ -90,4 +102,4 @@ assertErrorCode(input, {$out: outputInSystem.getName()}, 17385);
90102
assert(!collectionExists(outputInSystem));
91103

92104
// shoudn't leave temp collections laying around
93-
assert.eq([], db.system.namespaces.find({name: /tmp\.agg_out/}).toArray());
105+
assert.eq([], listCollections(/tmp\.agg_out/));

jstests/auth/indexSystemUsers.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ assert.writeError(adminDB.exploit.system.indexes.insert({ ns: "admin.system.user
2121
unique: true,
2222
dropDups: true }));
2323
// Make sure that no indexes were built.
24-
assert.eq(null,
25-
adminDB.system.namespaces.findOne(
24+
var collectionInfosCursor = adminDB.runCommand("listCollections", { filter:
2625
{$and : [{name : /^admin\.system\.users\.\$/},
2726
{name : {$ne : "admin.system.users.$_id_"}},
28-
{name : {$ne : "admin.system.users.$user_1_db_1"}} ]}));
27+
{name : {$ne : "admin.system.users.$user_1_db_1"}} ]}});
28+
29+
assert.eq([], new DBCommandCursor(adminDB.getMongo(), collectionInfosCursor).toArray());
2930
adminDB.logout();
3031

3132
adminDB.auth('admin','x');

jstests/core/apitest_db.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ dd( "c" );
2727
/*
2828
* test createCollection
2929
*/
30-
30+
3131
db.getCollection( "test" ).drop();
3232
db.getCollectionNames().forEach( function(x) { assert(x != "test"); });
3333

3434
dd( "d" );
35-
35+
3636
db.createCollection("test");
3737
var found = false;
3838
db.getCollectionNames().forEach( function(x) { if (x == "test") found = true; });
39-
assert(found, "found test.test in system.namespaces");
39+
assert(found, "found test.test in collection infos");
4040

4141
// storageEngine in collection options must:
4242
// - be a document

jstests/core/index4.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ t.save( { name : "clusterstock" ,
2020

2121
// this should fail, not allowed -- we confirm that.
2222
t.ensureIndex( { instances : { pool : 1 } } );
23-
assert.eq( 0, db.system.indexes.find( {ns:"test.index4",name:{$ne:"_id_"}} ).count(), "no indexes should be here yet");
23+
assert.eq( 1, t.getIndexes().length, "no indexes other than _id should be here yet");
2424

2525
t.ensureIndex( { "instances.pool" : 1 } );
2626

jstests/multiVersion/libs/verify_collection_data.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ createCollectionWithData = function (db, collectionName, dataGenerator) {
4444
numIndexes++;
4545
}
4646

47-
// Make sure we actually added all the indexes we thing we added. +1 for the _id index.
48-
assert.eq(db.system.indexes.find({"ns" : db.toString() + "." + collection.getName()}).count(),
49-
numIndexes + 1);
47+
// Make sure we actually added all the indexes we think we added. +1 for the _id index.
48+
assert.eq(collection.getIndexes().length, numIndexes + 1);
5049

5150
var numInserted = 0;
5251
while (dataGenerator.data.hasNext()) {
@@ -78,7 +77,10 @@ function CollectionDataValidator() {
7877
this.recordCollectionData = function (collection) {
7978

8079
// Save the indexes for this collection for later comparison
81-
indexData = collection.getDB().system.indexes.find({"ns" : collection.getFullName()}).sort({"name":1}).toArray();
80+
indexData = collection.getIndexes().sort(function(a,b) {
81+
if (a.name > b.name) return 1;
82+
else return -1;
83+
});
8284

8385
// Save the data for this collection for later comparison
8486
collectionData = collection.find().sort({"_id":1}).toArray();
@@ -137,7 +139,10 @@ function CollectionDataValidator() {
137139
assert.docEq(collectionStats, newCollectionStats, "collection metadata not equal");
138140

139141
// Get the indexes for this collection
140-
var newIndexData = collection.getDB().system.indexes.find({"ns" : collection.getFullName()}).sort({"name":1}).toArray();
142+
var newIndexData = collection.getIndexes().sort(function(a,b) {
143+
if (a.name > b.name) return 1;
144+
else return -1;
145+
});
141146
for (var i = 0; i < newIndexData.length; i++) {
142147
assert.docEq(indexData[i], newIndexData[i], "indexes not equal");
143148
}
@@ -164,7 +169,7 @@ function collectionDataValidatorTests() {
164169
collection = createCollectionWithData(db, "test", myGenerator);
165170
myValidator = new CollectionDataValidator();
166171
myValidator.recordCollectionData(collection);
167-
db.test.dropIndex(db.system.indexes.findOne({"key.a": { "$exists" : true } }).key);
172+
db.test.dropIndex(db.test.getIndexKeys().filter(function(key) { return key.a != null })[0]);
168173
assert.throws(myValidator.validateCollectionData, [collection], "Validation function should have thrown since we modified the collection");
169174

170175

@@ -186,7 +191,7 @@ function collectionDataValidatorTests() {
186191
collection = createCollectionWithData(db, "test", myGenerator);
187192
myValidator = new CollectionDataValidator();
188193
myValidator.recordCollectionData(collection);
189-
db.test.dropIndex(db.system.indexes.findOne({"key.a": { "$exists" : true } }).key);
194+
db.test.dropIndex(db.test.getIndexKeys().filter(function(key) { return key.a != null })[0]);
190195
assert.throws(myValidator.validateCollectionData, [collection], "Validation function should have thrown since we modified the collection");
191196

192197

jstests/noPassthroughWithMongod/indexbg_drop.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ jsTest.log("Starting background indexing for test of: " + tojson(dc));
5656
masterDB.getCollection(collection).ensureIndex({b:1});
5757

5858
masterDB.getCollection(collection).ensureIndex( {i:1}, {background:true} );
59-
assert.eq(3, masterDB.system.indexes.count( {ns:dbname + "." + collection}, {background:true} ) );
59+
assert.eq(3, masterDB.getCollection(collection).getIndexes().length );
6060

6161
// Wait for the secondary to get the index entry
62-
assert.soon(
63-
function() { return 3 == secondDB.system.indexes.count( {ns:dbname + "." + collection} ); },
62+
assert.soon(
63+
function() { return 3 == secondDB.getCollection(collection).getIndexes().length; },
6464
"index not created on secondary (prior to drop)", 240000 );
6565

66-
jsTest.log("Index created and system.indexes entry exists on secondary");
66+
jsTest.log("Index created and index entry exists on secondary");
6767

6868

6969
// make sure the index build has started on secondary
@@ -90,17 +90,17 @@ jsTest.log("Waiting on replication");
9090
replTest.awaitReplication();
9191

9292
print("index list on master:");
93-
masterDB.system.indexes.find().forEach(printjson);
93+
masterDB.getCollection(collection).getIndexes().forEach(printjson);
9494

9595
// we need to assert.soon because the drop only marks the index for removal
9696
// the removal itself is asynchronous and may take another moment before it happens
9797
var i = 0;
9898
assert.soon( function() {
9999
print("index list on secondary (run " + i + "):");
100-
secondDB.system.indexes.find().forEach(printjson);
101-
100+
secondDB.getCollection(collection).getIndexes().forEach(printjson);
101+
102102
i++;
103-
return 1 === secondDB.system.indexes.count();
103+
return 1 === secondDB.getCollection(collection).getIndexes().length;
104104
}, "secondary did not drop index"
105105
);
106106

jstests/noPassthroughWithMongod/indexbg_interrupts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ for (var idx = 0; idx < dropAction.length; idx++) {
8181
return 2 == secondDB.getCollection(collection).getIndexes().length;
8282
}, "index not created on secondary", 240000 );
8383

84-
jsTest.log("Index created and system.indexes entry exists on secondary");
84+
jsTest.log("Index created and index info exists on secondary");
8585

8686
jsTest.log("running command " + JSON.stringify(dc));
8787
assert.commandWorked(masterDB.runCommand( dc ));

jstests/noPassthroughWithMongod/indexbg_restart_sigkill_secondary_noretry.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ if (0) {
7575

7676
jsTest.log("Starting background indexing");
7777
masterDB.jstests_bgsec.ensureIndex( {i:1}, {background:true} );
78-
assert.eq(2, masterDB.system.indexes.count( {ns:"bgIndexNoRetrySec.jstests_bgsec"} ) );
78+
assert.eq(2, masterDB.jstests_bgsec.getIndexes().length);
7979

8080
// Do one more write, so that later on, the secondary doesn't restart with the index build
8181
// as the last op in the oplog -- it will redo this op otherwise.
@@ -96,21 +96,21 @@ if (0) {
9696
// Make sure secondary comes back
9797
assert.soon( function() {
9898
try {
99-
secondDB.system.namespaces.count(); // trigger a reconnect if needed
100-
return true;
99+
secondDB.isMaster(); // trigger a reconnect if needed
100+
return true;
101101
} catch (e) {
102102
return false;
103103
}
104104
} , "secondary didn't restart", 60000, 1000);
105105

106-
assert_trueTimeout(
107-
function() {
108-
return 2 == secondDB.system.indexes.count( {ns:"bgIndexNoRetrySec.jstests_bgsec"} );
106+
assert_trueTimeout(
107+
function() {
108+
return 2 == secondDB.jstests_bgsec.getIndexes().length;
109109
},
110110
"index created on secondary after restart with --noIndexBuildRetry",
111111
30000, 200);
112112

113-
assert.neq(2, secondDB.system.indexes.count( {ns:"bgIndexNoRetrySec.jstests_bgsec"} ));
113+
assert.neq(2, secondDB.jstests_bgsec.getIndexes().length );
114114
replTest.stopSet();
115115
}());
116116

jstests/replsets/index_restart_secondary.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ if (conns[0].getDB('test').serverBuildInfo().bits !== 32) {
5959
// Make sure secondary comes back
6060
assert.soon( function() {
6161
try {
62-
secondDB.system.namespaces.count(); // trigger a reconnect if needed
63-
return true;
62+
secondDB.isMaster(); // trigger a reconnect if needed
63+
return true;
6464
} catch (e) {
6565
return false;
6666
}

jstests/sharding/features1.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ assert.eq( 5 , b.foo.getIndexKeys().length , "c index 3" );
6060

6161
db.foo2.ensureIndex( { a : 1 } );
6262
s.sync();
63-
printjson( db.system.indexes.find( { ns : "test.foo2" } ).toArray() );
63+
printjson( db.foo2.getIndexes() );
6464
assert( s.admin.runCommand( { shardcollection : "test.foo2" , key : { num : 1 } } ).ok , "shard with index" );
6565

6666
db.foo3.ensureIndex( { a : 1 } , true );
6767
s.sync();
68-
printjson( db.system.indexes.find( { ns : "test.foo3" } ).toArray() );
68+
printjson( db.foo3.getIndexes() );
6969
assert( ! s.admin.runCommand( { shardcollection : "test.foo3" , key : { num : 1 } } ).ok , "shard with unique index" );
7070

7171
db.foo7.ensureIndex( { num : 1 , a : 1 } , true );
7272
s.sync();
73-
printjson( db.system.indexes.find( { ns : "test.foo7" } ).toArray() );
73+
printjson( db.foo7.getIndexes() );
7474
assert( s.admin.runCommand( { shardcollection : "test.foo7" , key : { num : 1 } } ).ok , "shard with ok unique index" );
7575

7676

@@ -153,7 +153,7 @@ db.foo6.save( { a : 3 } );
153153
db.foo6.save( { a : 3 } );
154154
db.foo6.ensureIndex( { a : 1 } );
155155
s.sync();
156-
printjson( db.system.indexes.find( { ns : "test.foo6" } ).toArray() );
156+
printjson( db.foo6.getIndexes() );
157157

158158
assert.eq( 2 , db.foo6.group( { key : { a : 1 } , initial : { count : 0 } ,
159159
reduce : function(z,prev){ prev.count++; } } ).length );

0 commit comments

Comments
 (0)