@@ -61,7 +61,7 @@ module.exports = (common) => {
61
61
describe ( '.pubsub' , function ( ) {
62
62
this . timeout ( 20 * 1000 )
63
63
64
- const topic = 'pubsub-tests'
64
+ const getTopic = ( ) => 'pubsub-tests-' + Math . random ( )
65
65
66
66
describe ( 'callback API' , ( ) => {
67
67
let ipfs1
@@ -98,20 +98,23 @@ module.exports = (common) => {
98
98
describe ( 'single node' , ( ) => {
99
99
describe ( '.publish' , ( ) => {
100
100
it ( 'errors on string messags' , ( done ) => {
101
+ const topic = getTopic ( )
101
102
ipfs1 . pubsub . publish ( topic , 'hello friend' , ( err ) => {
102
103
expect ( err ) . to . exist ( )
103
104
done ( )
104
105
} )
105
106
} )
106
107
107
108
it ( 'message from buffer' , ( done ) => {
109
+ const topic = getTopic ( )
108
110
ipfs1 . pubsub . publish ( topic , Buffer . from ( 'hello friend' ) , done )
109
111
} )
110
112
} )
111
113
112
114
describe ( '.subscribe' , ( ) => {
113
115
it ( 'to one topic' , ( done ) => {
114
116
const check = makeCheck ( 2 , done )
117
+ const topic = getTopic ( )
115
118
116
119
const handler = ( msg ) => {
117
120
expect ( msg . data . toString ( ) ) . to . equal ( 'hi' )
@@ -136,6 +139,8 @@ module.exports = (common) => {
136
139
} )
137
140
138
141
it ( 'attaches multiple event listeners' , ( done ) => {
142
+ const topic = getTopic ( )
143
+
139
144
const check = makeCheck ( 3 , done )
140
145
const handler1 = ( msg ) => {
141
146
expect ( msg . data . toString ( ) ) . to . eql ( 'hello' )
@@ -176,6 +181,7 @@ module.exports = (common) => {
176
181
177
182
it ( 'discover options' , ( done ) => {
178
183
const check = makeCheck ( 2 , done )
184
+ const topic = getTopic ( )
179
185
180
186
const handler = ( msg ) => {
181
187
expect ( msg . data . toString ( ) ) . to . be . eql ( 'hi' )
@@ -210,6 +216,7 @@ module.exports = (common) => {
210
216
211
217
describe ( '.peers' , ( ) => {
212
218
it ( 'does not error when not subscribed to a topic' , ( done ) => {
219
+ const topic = getTopic ( )
213
220
ipfs1 . pubsub . peers ( topic , ( err , peers ) => {
214
221
expect ( err ) . to . not . exist ( )
215
222
// Should be empty() but as mentioned below go-ipfs returns more than it should
@@ -226,6 +233,7 @@ module.exports = (common) => {
226
233
const sub2 = ( msg ) => { }
227
234
const sub3 = ( msg ) => { }
228
235
236
+ const topic = getTopic ( )
229
237
const topicOther = topic + 'different topic'
230
238
231
239
series ( [
@@ -254,6 +262,7 @@ module.exports = (common) => {
254
262
const sub1 = ( msg ) => { }
255
263
const sub2 = ( msg ) => { }
256
264
const sub3 = ( msg ) => { }
265
+ const topic = getTopic ( )
257
266
258
267
series ( [
259
268
( cb ) => ipfs1 . pubsub . subscribe ( topic , sub1 , cb ) ,
@@ -274,6 +283,7 @@ module.exports = (common) => {
274
283
const sub1 = ( msg ) => { }
275
284
const sub2 = ( msg ) => { }
276
285
const sub3 = ( msg ) => { }
286
+ const topic = getTopic ( )
277
287
278
288
series ( [
279
289
( cb ) => ipfs1 . pubsub . subscribe ( topic , sub1 , cb ) ,
@@ -305,6 +315,7 @@ module.exports = (common) => {
305
315
306
316
it ( 'list with 1 subscribed topic' , ( done ) => {
307
317
const sub1 = ( msg ) => { }
318
+ const topic = getTopic ( )
308
319
309
320
ipfs1 . pubsub . subscribe ( topic , sub1 , ( err ) => {
310
321
expect ( err ) . to . not . exist ( )
@@ -358,6 +369,7 @@ module.exports = (common) => {
358
369
it ( 'receive messages from different node' , ( done ) => {
359
370
const check = makeCheck ( 3 , done )
360
371
const expectedString = 'hello from the other side'
372
+ const topic = getTopic ( )
361
373
362
374
const sub1 = ( msg ) => {
363
375
expect ( msg . data . toString ( ) ) . to . be . eql ( expectedString )
@@ -388,6 +400,7 @@ module.exports = (common) => {
388
400
const check = makeCheck ( 3 , done )
389
401
const expectedHex = 'a36161636179656162830103056164a16466666666f4'
390
402
const buffer = Buffer . from ( expectedHex , 'hex' )
403
+ const topic = getTopic ( )
391
404
392
405
const sub1 = ( msg ) => {
393
406
try {
@@ -428,6 +441,7 @@ module.exports = (common) => {
428
441
const inbox1 = [ ]
429
442
const inbox2 = [ ]
430
443
const outbox = [ 'hello' , 'world' , 'this' , 'is' , 'pubsub' ]
444
+ const topic = getTopic ( )
431
445
432
446
const check = makeCheck ( outbox . length * 3 , ( err ) => {
433
447
ipfs1 . pubsub . unsubscribe ( topic , sub1 )
@@ -479,6 +493,7 @@ module.exports = (common) => {
479
493
it ( 'call publish 1k times' , ( done ) => {
480
494
const count = 1000
481
495
let sendCount = 0
496
+ const topic = getTopic ( )
482
497
483
498
whilst (
484
499
( ) => sendCount < count ,
@@ -499,6 +514,7 @@ module.exports = (common) => {
499
514
let receivedCount = 0
500
515
let startTime
501
516
let counter = 0
517
+ const topic = getTopic ( )
502
518
503
519
const sub1 = ( msg ) => {
504
520
// go-ipfs can't send messages in order when there are
@@ -555,7 +571,7 @@ module.exports = (common) => {
555
571
let sendCount = 0
556
572
const handlers = [ ]
557
573
558
- const someTopic = 'some-other-topic'
574
+ const someTopic = getTopic ( )
559
575
560
576
whilst (
561
577
( ) => sendCount < count ,
@@ -608,6 +624,8 @@ module.exports = (common) => {
608
624
} )
609
625
610
626
it ( '.subscribe and .publish' , ( ) => {
627
+ const topic = getTopic ( )
628
+
611
629
const sub = ( msg ) => {
612
630
expect ( msg . data . toString ( ) ) . to . be . eql ( 'hi' )
613
631
ipfs1 . pubsub . unsubscribe ( topic , sub )
@@ -619,6 +637,7 @@ module.exports = (common) => {
619
637
620
638
it ( '.peers' , ( ) => {
621
639
const sub = ( msg ) => { }
640
+ const topic = getTopic ( )
622
641
623
642
return ipfs1 . pubsub . subscribe ( topic , sub )
624
643
. then ( ( ) => ipfs1 . pubsub . peers ( topic ) )
0 commit comments