@@ -156,15 +156,24 @@ describe('pubsub', function() {
156156 var topic ;
157157
158158 before ( function ( done ) {
159- // Create a new test topic.
160159 pubsub . createTopic ( TOPIC_NAME , function ( err , newTopic ) {
161160 assert . ifError ( err ) ;
162161 topic = newTopic ;
163162
164- // Create subscriptions.
165- async . parallel ( SUBSCRIPTIONS . map ( function ( sub ) {
166- return topic . subscribe . bind ( topic , sub . name , sub . options ) ;
167- } ) , done ) ;
163+ function createSubscription ( subscription , callback ) {
164+ topic . subscribe ( subscription . name , subscription . options , callback ) ;
165+ }
166+
167+ async . each ( SUBSCRIPTIONS , createSubscription , function ( err ) {
168+ if ( err ) {
169+ done ( err ) ;
170+ return ;
171+ }
172+
173+ async . times ( 10 , function ( _ , next ) {
174+ topic . publish ( { data : 'hello' } , next ) ;
175+ } , done ) ;
176+ } ) ;
168177 } ) ;
169178 } ) ;
170179
@@ -248,125 +257,66 @@ describe('pubsub', function() {
248257 it ( 'should be able to pull and ack' , function ( done ) {
249258 var subscription = topic . subscription ( SUB_NAMES [ 0 ] ) ;
250259
251- topic . publish ( { data : 'hello' } , function ( err ) {
260+ subscription . pull ( {
261+ returnImmediately : true ,
262+ maxResults : 1
263+ } , function ( err , msgs ) {
252264 assert . ifError ( err ) ;
253265
254- subscription . pull ( {
255- returnImmediately : false ,
256- maxResults : 1
257- } , function ( err , msgs ) {
258- assert . ifError ( err ) ;
259- subscription . ack ( msgs [ 0 ] . ackId , done ) ;
260- } ) ;
266+ assert . strictEqual ( msgs . length , 1 ) ;
267+
268+ subscription . ack ( msgs [ 0 ] . ackId , done ) ;
261269 } ) ;
262270 } ) ;
263271
264272 it ( 'should be able to set a new ack deadline' , function ( done ) {
265273 var subscription = topic . subscription ( SUB_NAMES [ 0 ] ) ;
266274
267- topic . publish ( { data : 'hello' } , function ( err ) {
275+ subscription . pull ( {
276+ returnImmediately : true ,
277+ maxResults : 1
278+ } , function ( err , msgs ) {
268279 assert . ifError ( err ) ;
269280
270- subscription . pull ( {
271- returnImmediately : false ,
272- maxResults : 1
273- } , function ( err , msgs ) {
274- assert . ifError ( err ) ;
275-
276- var options = {
277- ackIds : [ msgs [ 0 ] . ackId ] ,
278- seconds : 10
279- } ;
280- subscription . setAckDeadline ( options , done ) ;
281- } ) ;
282- } ) ;
283- } ) ;
284-
285- it ( 'should receive the published message' , function ( done ) {
286- var subscription = topic . subscription ( SUB_NAMES [ 1 ] ) ;
281+ assert . strictEqual ( msgs . length , 1 ) ;
287282
288- topic . publish ( [
289- { data : 'hello' } ,
290- { data : 'hello' } ,
291- { data : 'hello' } ,
292- { data : 'hello' } ,
293- { data : 'hello' } ,
294- { data : 'hello' } ,
295- { data : 'hello' } ,
296- { data : 'hello' } ,
297- { data : 'hello' } ,
298- { data : 'hello' }
299- ] , function ( err ) {
300- assert . ifError ( err ) ;
283+ var options = {
284+ ackIds : [ msgs [ 0 ] . ackId ] ,
285+ seconds : 10
286+ } ;
301287
302- subscription . pull ( {
303- returnImmediately : false ,
304- maxResults : 1
305- } , function ( err , msgs ) {
306- assert . ifError ( err ) ;
307- assert . equal ( msgs [ 0 ] . data , 'hello' ) ;
308- subscription . ack ( msgs [ 0 ] . ackId , done ) ;
309- } ) ;
288+ subscription . setAckDeadline ( options , done ) ;
310289 } ) ;
311290 } ) ;
312291
313- it ( 'should receive a raw published message' , function ( done ) {
314- var subscription = topic . subscription ( SUB_NAMES [ 0 ] ) ;
292+ it ( 'should receive the published message' , function ( done ) {
293+ var subscription = topic . subscription ( SUB_NAMES [ 1 ] ) ;
315294
316- topic . publish ( [
317- { data : 'hello' } ,
318- { data : 'hello' } ,
319- { data : 'hello' } ,
320- { data : 'hello' } ,
321- { data : 'hello' } ,
322- { data : 'hello' } ,
323- { data : 'hello' } ,
324- { data : 'hello' } ,
325- { data : 'hello' } ,
326- { data : 'hello' }
327- ] , function ( err ) {
295+ subscription . pull ( {
296+ returnImmediately : true ,
297+ maxResults : 1
298+ } , function ( err , msgs ) {
328299 assert . ifError ( err ) ;
329-
330- subscription . pull ( {
331- returnImmediately : false ,
332- maxResults : 1
333- } , function ( err , msgs ) {
334- assert . ifError ( err ) ;
335- assert . equal ( msgs [ 0 ] . data , 'hello' ) ;
336- subscription . ack ( msgs [ 0 ] . ackId , done ) ;
337- } ) ;
300+ assert . strictEqual ( msgs . length , 1 ) ;
301+ assert . equal ( msgs [ 0 ] . data , 'hello' ) ;
302+ subscription . ack ( msgs [ 0 ] . ackId , done ) ;
338303 } ) ;
339304 } ) ;
340305
341306 it ( 'should receive the chosen amount of results' , function ( done ) {
342307 var subscription = topic . subscription ( SUB_NAMES [ 1 ] ) ;
343- var opts = { returnImmediately : false , maxResults : 3 } ;
344-
345- topic . publish ( [
346- { data : 'hello' } ,
347- { data : 'hello' } ,
348- { data : 'hello' } ,
349- { data : 'hello' } ,
350- { data : 'hello' } ,
351- { data : 'hello' } ,
352- { data : 'hello' } ,
353- { data : 'hello' } ,
354- { data : 'hello' } ,
355- { data : 'hello' }
356- ] , function ( err ) {
357- assert . ifError ( err ) ;
308+ var opts = { returnImmediately : true , maxResults : 3 } ;
358309
359- subscription . pull ( opts , function ( err , messages ) {
360- assert . ifError ( err ) ;
310+ subscription . pull ( opts , function ( err , messages ) {
311+ assert . ifError ( err ) ;
361312
362- assert . equal ( messages . length , opts . maxResults ) ;
313+ assert . equal ( messages . length , opts . maxResults ) ;
363314
364- var ackIds = messages . map ( function ( message ) {
365- return message . ackId ;
366- } ) ;
367-
368- subscription . ack ( ackIds , done ) ;
315+ var ackIds = messages . map ( function ( message ) {
316+ return message . ackId ;
369317 } ) ;
318+
319+ subscription . ack ( ackIds , done ) ;
370320 } ) ;
371321 } ) ;
372322 } ) ;
0 commit comments