Skip to content

Commit 3283571

Browse files
author
Devendra
committed
modifying tests a bit
1 parent c61207e commit 3283571

File tree

1 file changed

+84
-69
lines changed

1 file changed

+84
-69
lines changed

node.js/tests/test.js

+84-69
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ describe('Pubnub', function () {
163163
describe('#subscribe()', function () {
164164

165165
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+
}
166170
var random = get_random();
167171
var ch = 'channel-' + random;
168172
var chg = 'channel-group-' + random;
@@ -177,95 +181,106 @@ describe('Pubnub', function () {
177181
pubnub.channel_group_list_channels({
178182
'channel_group' : chg,
179183
'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(){
194198
pubnub.publish({
195-
'channel' : chwc,
196-
message : 'message' + chwc,
199+
'channel' : ch,
200+
message : 'message' + ch,
197201
callback : function(r) {
198-
assert.ok(true, 'message published');
202+
console.log(4 + ' : PUBLISHED ' + 'message' + ch);
203+
assert.ok(true, 'message published');
199204
pubnub.publish({
200-
'channel' : chgc,
201-
message : 'message' + chgc,
205+
'channel' : chwc,
206+
message : 'message' + chwc,
202207
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+
})
205222
},
206223
error : function(r) {
207224
assert.ok(false, 'error occurred in publish');
208225
}
209-
210226
})
211227
},
212228
error : function(r) {
213229
assert.ok(false, 'error occurred in publish');
214230
}
215231
})
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);
256273
},
257274
'error' : function(r) {
258275
assert.ok(false, "error occurred in adding channel to group");
259276
}
260277

261-
});
262-
},
263-
'error' : function(r) {
264-
ok(false, "error occurred");
265-
}
266278
})
267-
268-
279+
},
280+
'error' : function(r) {
281+
ok(false, "error occurred");
282+
}
283+
})
269284
});
270285

271286

0 commit comments

Comments
 (0)