diff --git a/packages/mongo-livedata/mongo_livedata_tests.js b/packages/mongo-livedata/mongo_livedata_tests.js index eea9dbed07..6406d18824 100644 --- a/packages/mongo-livedata/mongo_livedata_tests.js +++ b/packages/mongo-livedata/mongo_livedata_tests.js @@ -24,6 +24,10 @@ if (Meteor.isServer) { Meteor.publish('c-' + name, function () { return c.find(); }); + }, + dropInsecureCollection: function(name) { + var c = COLLECTIONS[name]; + c._dropCollection(); } }); } @@ -2338,14 +2342,21 @@ _.each( ['STRING', 'MONGO'], function (idGeneration) { testAsyncMulti('mongo-livedata - consistent _id generation ' + name + ', ' + repetitions + ' repetitions on ' + collectionCount + ' collections, idGeneration=' + idGeneration, [ function (test, expect) { var collectionOptions = { idGeneration: idGeneration }; + var cleanups = this.cleanups = []; this.collections = _.times(collectionCount, function () { var collectionName = "consistentid_" + Random.id(); if (Meteor.isClient) { Meteor.call('createInsecureCollection', collectionName, collectionOptions); Meteor.subscribe('c-' + collectionName, expect()); + cleanups.push(function (expect) { Meteor.call('dropInsecureCollection', collectionName, expect(function () {})); }); } - return (COLLECTIONS[collectionName] = new Meteor.Collection(collectionName, collectionOptions)); + var collection = new Meteor.Collection(collectionName, collectionOptions); + if (Meteor.isServer) { + cleanups.push(function () { collection._dropCollection(); }); + } + COLLECTIONS[collectionName] = collection; + return collection; }); }, function (test, expect) { // now run the actual test @@ -2354,6 +2365,11 @@ _.each( ['STRING', 'MONGO'], function (idGeneration) { fn(test, expect, this.collections[j], i); } } + }, function (test, expect) { + // Run any registered cleanup functions (e.g. to drop collections) + _.each(this.cleanups, function(cleanup) { + cleanup(expect); + }); }]); });