@@ -163,6 +163,10 @@ describe('Pubnub', function () {
163
163
describe ( '#subscribe()' , function ( ) {
164
164
165
165
it ( 'should be able to handle wildcard, channel group and channel together' , function ( done ) {
166
+ var count = 3 ;
167
+ function d ( ) {
168
+ if ( -- count == 0 ) done ( ) ;
169
+ }
166
170
var random = get_random ( ) ;
167
171
var ch = 'channel-' + random ;
168
172
var chg = 'channel-group-' + random ;
@@ -177,95 +181,106 @@ describe('Pubnub', function () {
177
181
pubnub . channel_group_list_channels ( {
178
182
'channel_group' : chg ,
179
183
'callback' : function ( r ) {
180
- pubnub . subscribe ( {
181
- channel : ch ,
182
- connect : function ( ) {
183
- pubnub . subscribe ( {
184
- channel : chw ,
185
- connect : function ( ) {
186
- pubnub . subscribe ( {
187
- channel_group : chg ,
188
- connect : function ( ) {
189
- pubnub . publish ( {
190
- 'channel' : ch ,
191
- message : 'message' + ch ,
192
- callback : function ( r ) {
193
- assert . ok ( true , 'message published' ) ;
184
+ console . log ( 1 ) ;
185
+ setTimeout ( function ( ) {
186
+ pubnub . subscribe ( {
187
+ channel : ch ,
188
+ connect : function ( ) {
189
+ console . log ( 2 ) ;
190
+ pubnub . subscribe ( {
191
+ channel : chw ,
192
+ connect : function ( ) {
193
+ console . log ( 3 ) ;
194
+ pubnub . subscribe ( {
195
+ channel_group : chg ,
196
+ connect : function ( ) {
197
+ setTimeout ( function ( ) {
194
198
pubnub . publish ( {
195
- 'channel' : chwc ,
196
- message : 'message' + chwc ,
199
+ 'channel' : ch ,
200
+ message : 'message' + ch ,
197
201
callback : function ( r ) {
198
- assert . ok ( true , 'message published' ) ;
202
+ console . log ( 4 + ' : PUBLISHED ' + 'message' + ch ) ;
203
+ assert . ok ( true , 'message published' ) ;
199
204
pubnub . publish ( {
200
- 'channel' : chgc ,
201
- message : 'message' + chgc ,
205
+ 'channel' : chwc ,
206
+ message : 'message' + chwc ,
202
207
callback : function ( r ) {
203
- assert . ok ( true , 'message published' ) ;
204
-
208
+ console . log ( 5 + ' : PUBLISHED ' + 'message' + chwc ) ;
209
+ assert . ok ( true , 'message published' ) ;
210
+ pubnub . publish ( {
211
+ 'channel' : chgc ,
212
+ message : 'message' + chgc ,
213
+ callback : function ( r ) {
214
+ console . log ( 9 + ' : PUBLISHED ' + 'message' + chgc )
215
+ assert . ok ( true , 'message published' ) ;
216
+ } ,
217
+ error : function ( r ) {
218
+ assert . ok ( false , 'error occurred in publish' ) ;
219
+ }
220
+
221
+ } )
205
222
} ,
206
223
error : function ( r ) {
207
224
assert . ok ( false , 'error occurred in publish' ) ;
208
225
}
209
-
210
226
} )
211
227
} ,
212
228
error : function ( r ) {
213
229
assert . ok ( false , 'error occurred in publish' ) ;
214
230
}
215
231
} )
216
- } ,
217
- error : function ( r ) {
218
- assert . ok ( false , 'error occurred in publish' ) ;
219
- }
220
-
221
- } )
222
- } ,
223
- callback : function ( response ) {
224
- assert . deepEqual ( response , 'message' + chgc ) ;
225
- pubnub . unsubscribe ( { channel : chgc } ) ;
226
- done ( ) ;
227
- } ,
228
- error : function ( ) {
229
- assert . ok ( false ) ;
230
- pubnub . unsubscribe ( { channel : ch } ) ;
231
- done ( ) ;
232
- }
233
- } ) ;
234
- } ,
235
- callback : function ( response ) {
236
- assert . deepEqual ( response , 'message' + chwc ) ;
237
- //pubnub.unsubscribe({channel: chwc});
238
- } ,
239
- error : function ( ) {
240
- assert . ok ( false ) ;
241
- pubnub . unsubscribe ( { channel : ch } ) ;
242
- done ( ) ;
243
- }
244
- } ) ;
245
- } ,
246
- callback : function ( response ) {
247
- assert . deepEqual ( response , 'message' + ch ) ;
248
- pubnub . unsubscribe ( { channel : ch } ) ;
249
- } ,
250
- error : function ( ) {
251
- assert . ok ( false ) ;
252
- pubnub . unsubscribe ( { channel : ch } ) ;
253
- done ( ) ;
254
- }
255
- } )
232
+ } , 5000 ) ;
233
+ } ,
234
+ callback : function ( response ) {
235
+ console . log ( 6 + ' : ' + response ) ;
236
+ assert . deepEqual ( response , 'message' + chgc ) ;
237
+ pubnub . unsubscribe ( { channel_group : chg } ) ;
238
+ d ( ) ;
239
+ } ,
240
+ error : function ( ) {
241
+ assert . ok ( false ) ;
242
+ pubnub . unsubscribe ( { channel : ch } ) ;
243
+ done ( ) ;
244
+ }
245
+ } ) ;
246
+ } ,
247
+ callback : function ( response ) {
248
+ console . log ( 7 + ' : ' + response ) ;
249
+ assert . deepEqual ( response , 'message' + chwc ) ;
250
+ d ( ) ;
251
+ //pubnub.unsubscribe({channel: chw});
252
+ } ,
253
+ error : function ( ) {
254
+ assert . ok ( false ) ;
255
+ pubnub . unsubscribe ( { channel : ch } ) ;
256
+ done ( ) ;
257
+ }
258
+ } ) ;
259
+ } ,
260
+ callback : function ( response ) {
261
+ console . log ( 8 + ' : ' + response ) ;
262
+ assert . deepEqual ( response , 'message' + ch ) ;
263
+ //pubnub.unsubscribe({channel: ch});
264
+ d ( ) ;
265
+ } ,
266
+ error : function ( ) {
267
+ assert . ok ( false ) ;
268
+ pubnub . unsubscribe ( { channel : ch } ) ;
269
+ done ( ) ;
270
+ }
271
+ } )
272
+ } , 5000 ) ;
256
273
} ,
257
274
'error' : function ( r ) {
258
275
assert . ok ( false , "error occurred in adding channel to group" ) ;
259
276
}
260
277
261
- } ) ;
262
- } ,
263
- 'error' : function ( r ) {
264
- ok ( false , "error occurred" ) ;
265
- }
266
278
} )
267
-
268
-
279
+ } ,
280
+ 'error' : function ( r ) {
281
+ ok ( false , "error occurred" ) ;
282
+ }
283
+ } )
269
284
} ) ;
270
285
271
286
0 commit comments