From 9e69d98b32e18f68237989e10c59961170ffdf69 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Thu, 28 Aug 2014 21:34:59 -0400 Subject: [PATCH] tests: pubsub: fix racy tests. --- test/pubsub/index.js | 45 +++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/test/pubsub/index.js b/test/pubsub/index.js index 1da254d1e5e..d249ed97379 100644 --- a/test/pubsub/index.js +++ b/test/pubsub/index.js @@ -49,17 +49,18 @@ describe('Subscription', function() { projectId: 'test-project' }); conn.makeReq = function(method, path, qs, body, callback) { - switch (path) { - case 'subscriptions//subscriptions/test-project/sub1': - callback(null, {}); - return; - case 'subscriptions/pull': - callback(null, { ackId: 123 }); - return; + if (path === 'subscriptions//subscriptions/test-project/sub1') { + callback(null, {}); + return; + } + if (path === 'subscriptions/pull') { + callback(null, { ackId: 123 }); + return; } }; var sub = conn.subscribe('sub1', { autoAck: false }); - sub.on('message', function() { + sub.once('message', function() { + sub.close(); done(); }); }); @@ -69,22 +70,24 @@ describe('Subscription', function() { projectId: 'test-project' }); conn.makeReq = function(method, path, qs, body, callback) { - switch (path) { - case 'subscriptions//subscriptions/test-project/sub1': - callback(null, {}); - return; - case 'subscriptions/pull': - setImmediate(function() { - callback(null, { ackId: 123 }); - }); - return; - case 'subscriptions/acknowledge': - callback(null, true); - return; + if (path === 'subscriptions//subscriptions/test-project/sub1') { + callback(null, {}); + return; + } + if (path === 'subscriptions/pull') { + setImmediate(function() { + callback(null, { ackId: 123 }); + }); + return; + } + if (path === 'subscriptions/acknowledge') { + callback(null, true); + return; } }; var sub = conn.subscribe('sub1', { autoAck: true }); - sub.on('message', function() { + sub.once('message', function() { + sub.close(); done(); }); });