From 6dd9d590d796547aea2aa898a4f877116b75c024 Mon Sep 17 00:00:00 2001 From: Ryan Seys Date: Thu, 19 Feb 2015 16:46:13 -0500 Subject: [PATCH] Delete all subscriptions in pubsub reg tests --- regression/pubsub.js | 54 +++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/regression/pubsub.js b/regression/pubsub.js index 2529f06a027..58be491a442 100644 --- a/regression/pubsub.js +++ b/regression/pubsub.js @@ -57,15 +57,36 @@ describe('pubsub', function() { }); } + function deleteAllSubscriptions(callback) { + pubsub.getSubscriptions(function(err, subs) { + if(err) { + callback(err); + return; + } + async.parallel(subs.map(function(sub) { + return sub.delete.bind(sub); + }), callback); + }); + } + before(function(done) { - deleteAllTopics(function(err) { + deleteAllSubscriptions(function(err) { assert.ifError(err); - // Create new topics. - async.map(topicNames, pubsub.createTopic.bind(pubsub), done); + + deleteAllTopics(function(err) { + assert.ifError(err); + // Create new topics. + async.map(topicNames, pubsub.createTopic.bind(pubsub), done); + }); }); }); - after(deleteAllTopics); + after(function(done) { + deleteAllSubscriptions(function(err) { + assert.ifError(err); + deleteAllTopics(done); + }); + }); describe('Topic', function() { it('should be listed', function(done) { @@ -118,22 +139,29 @@ describe('pubsub', function() { var topic; before(function(done) { - deleteAllTopics(function(err) { + deleteAllSubscriptions(function(err) { assert.ifError(err); - // Create a new test topic. - pubsub.createTopic(TOPIC_NAME, function(err, newTopic) { + + deleteAllTopics(function(err) { assert.ifError(err); - topic = newTopic; - // Create subscriptions. - async.parallel(subscriptions.map(function(sub) { - return topic.subscribe.bind(topic, sub.name, sub.options); - }), done); + // Create a new test topic. + pubsub.createTopic(TOPIC_NAME, function(err, newTopic) { + assert.ifError(err); + topic = newTopic; + // Create subscriptions. + async.parallel(subscriptions.map(function(sub) { + return topic.subscribe.bind(topic, sub.name, sub.options); + }), done); + }); }); }); }); after(function(done) { - topic.delete(done); + deleteAllSubscriptions(function(err) { + assert.ifError(err); + deleteAllTopics(done); + }); }); it('should list all subscriptions registered to the topic', function(done) {