Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 522221c

Browse files
committed
Add test for pub/sub between clients
1 parent 4dd718b commit 522221c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/ipfs-api/pubsub.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-env mocha */
22
/* eslint max-nested-callbacks: ['error', 8] */
3+
/* globals apiClients */
34
'use strict'
45

56
const expect = require('chai').expect
@@ -96,4 +97,23 @@ describe('.pubsub', () => {
9697
}, 10)
9798
})
9899
})
100+
describe('multiple nodes pub/sub', () => {
101+
it('receive messages from different node', (done) => {
102+
const expectedString = 'hello from the other side'
103+
apiClients.a.pubsub.sub(topicName, (err, subscription) => {
104+
expect(err).to.not.exists
105+
subscription.on('data', (d) => {
106+
expect(d.data).to.be.equal(expectedString)
107+
subscription.cancel()
108+
done()
109+
})
110+
})
111+
setTimeout(() => {
112+
apiClients.b.pubsub.pub(topicName, expectedString, (err, result) => {
113+
expect(err).to.not.exist
114+
expect(result).to.equal(true)
115+
})
116+
}, 100)
117+
})
118+
})
99119
})

0 commit comments

Comments
 (0)