summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/indexbg_drop.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/noPassthroughWithMongod/indexbg_drop.js')
-rw-r--r--jstests/noPassthroughWithMongod/indexbg_drop.js53
1 files changed, 27 insertions, 26 deletions
diff --git a/jstests/noPassthroughWithMongod/indexbg_drop.js b/jstests/noPassthroughWithMongod/indexbg_drop.js
index 261ab342e48..863730ae35b 100644
--- a/jstests/noPassthroughWithMongod/indexbg_drop.js
+++ b/jstests/noPassthroughWithMongod/indexbg_drop.js
@@ -15,17 +15,20 @@ var collection = 'jstests_feh';
var size = 500000;
// Set up replica set
-var replTest = new ReplSetTest({ name: 'bgIndex', nodes: 3 });
+var replTest = new ReplSetTest({name: 'bgIndex', nodes: 3});
var nodes = replTest.nodeList();
printjson(nodes);
// We need an arbiter to ensure that the primary doesn't step down when we restart the secondary
replTest.startSet();
-replTest.initiate({"_id" : "bgIndex",
- "members" : [
- {"_id" : 0, "host" : nodes[0]},
- {"_id" : 1, "host" : nodes[1]},
- {"_id" : 2, "host" : nodes[2], "arbiterOnly" : true}]});
+replTest.initiate({
+ "_id": "bgIndex",
+ "members": [
+ {"_id": 0, "host": nodes[0]},
+ {"_id": 1, "host": nodes[1]},
+ {"_id": 2, "host": nodes[2], "arbiterOnly": true}
+ ]
+});
var master = replTest.getPrimary();
var second = replTest.getSecondary();
@@ -36,43 +39,43 @@ var secondId = replTest.getNodeId(second);
var masterDB = master.getDB(dbname);
var secondDB = second.getDB(dbname);
-
-var dc = {dropIndexes: collection, index: "i_1"};
+var dc = {
+ dropIndexes: collection,
+ index: "i_1"
+};
// set up collections
masterDB.dropDatabase();
jsTest.log("creating test data " + size + " documents");
Random.setRandomSeed();
var bulk = masterDB.getCollection(collection).initializeUnorderedBulkOp();
-for( i = 0; i < size; ++i ) {
- bulk.insert({ i: Random.rand() });
+for (i = 0; i < size; ++i) {
+ bulk.insert({i: Random.rand()});
}
assert.writeOK(bulk.execute());
jsTest.log("Starting background indexing for test of: " + tojson(dc));
// Add another index to be sure the drop command works.
-masterDB.getCollection(collection).ensureIndex({b:1});
+masterDB.getCollection(collection).ensureIndex({b: 1});
-masterDB.getCollection(collection).ensureIndex( {i:1}, {background:true} );
-assert.eq(3, masterDB.getCollection(collection).getIndexes().length );
+masterDB.getCollection(collection).ensureIndex({i: 1}, {background: true});
+assert.eq(3, masterDB.getCollection(collection).getIndexes().length);
// Wait for the secondary to get the index entry
-assert.soon(
- function() { return 3 == secondDB.getCollection(collection).getIndexes().length; },
- "index not created on secondary (prior to drop)", 240000 );
+assert.soon(function() {
+ return 3 == secondDB.getCollection(collection).getIndexes().length;
+}, "index not created on secondary (prior to drop)", 240000);
jsTest.log("Index created and index entry exists on secondary");
-
// make sure the index build has started on secondary
assert.soon(function() {
var curOp = secondDB.currentOp();
printjson(curOp);
- for (var i=0; i < curOp.inprog.length; i++) {
+ for (var i = 0; i < curOp.inprog.length; i++) {
try {
- if (curOp.inprog[i].insert.background){
-
- return true;
+ if (curOp.inprog[i].insert.background) {
+ return true;
}
} catch (e) {
// catchem if you can
@@ -81,9 +84,8 @@ assert.soon(function() {
return false;
}, "waiting for secondary bg index build", 20000, 10);
-
jsTest.log("dropping index");
-masterDB.runCommand( {dropIndexes: collection, index: "*"});
+masterDB.runCommand({dropIndexes: collection, index: "*"});
jsTest.log("Waiting on replication");
replTest.awaitReplication();
@@ -93,13 +95,12 @@ masterDB.getCollection(collection).getIndexes().forEach(printjson);
// we need to assert.soon because the drop only marks the index for removal
// the removal itself is asynchronous and may take another moment before it happens
var i = 0;
-assert.soon( function() {
+assert.soon(function() {
print("index list on secondary (run " + i + "):");
secondDB.getCollection(collection).getIndexes().forEach(printjson);
i++;
return 1 === secondDB.getCollection(collection).getIndexes().length;
- }, "secondary did not drop index"
-);
+}, "secondary did not drop index");
replTest.stopSet();