Compare commits

..

1 Commits

Author SHA1 Message Date
d3559f0e60 chore: add pubsub tests 2021-01-28 12:28:49 +01:00
4 changed files with 66 additions and 13 deletions

View File

@ -1,12 +1,3 @@
## [0.8.4](https://github.com/libp2p/js-interfaces/compare/v0.8.3...v0.8.4) (2021-03-22)
### Bug Fixes
* specify connection direction ([#86](https://github.com/libp2p/js-interfaces/issues/86)) ([3b960d5](https://github.com/libp2p/js-interfaces/commit/3b960d516f70f7e198574a736cb09000ddd7a94c))
## [0.8.3](https://github.com/libp2p/js-interfaces/compare/v0.8.2...v0.8.3) (2021-01-26)

View File

@ -1,6 +1,6 @@
{
"name": "libp2p-interfaces",
"version": "0.8.4",
"version": "0.8.3",
"description": "Interfaces for JS Libp2p",
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
"main": "src/index.js",

View File

@ -19,7 +19,7 @@ const connectionSymbol = Symbol.for('@libp2p/interface-connection/connection')
* @property {number} [close]
*
* @typedef {Object} ConectionStat
* @property {'inbound' | 'outbound'} direction - connection establishment direction
* @property {string} direction - connection establishment direction ("inbound" or "outbound").
* @property {Timeline} timeline - connection relevant events timestamp.
* @property {string} [multiplexer] - connection multiplexing identifier.
* @property {string} [encryption] - connection encryption method identifier.

View File

@ -307,9 +307,71 @@ module.exports = (common) => {
// line
// ◉────◎────◉
// a b c
// A subscribes and C publishes
before(() => { })
after(() => { })
let psA, psB, psC
// Create and start pubsub nodes
beforeEach(async () => {
[psA, psB, psC] = await common.setup(3)
// Start pubsub mpdes
;[psA, psB, psC].map((p) => p.start())
})
// Connect nodes
beforeEach(async () => {
await psA._libp2p.dial(psB.peerId)
await psB._libp2p.dial(psC.peerId)
// Wait for peers to be ready in pubsub
await pWaitFor(() =>
psA.peers.size === 1 &&
psC.peers.size === 1 &&
psA.peers.size === 1
)
})
afterEach(async () => {
sinon.restore()
;[psA, psB, psC].map((p) => p.stop())
await common.teardown()
})
it('exchange pubsub messages', async () => {
const defer = pDefer()
let counter = 0
const topic = 'Z'
function incMsg (msg) {
expect(uint8ArrayToString(msg.data)).to.equal('hey')
check()
}
function check () {
if (++counter === 1) {
psA.removeListener(topic, incMsg)
psB.removeListener(topic, incMsg)
psC.removeListener(topic, incMsg)
defer.resolve()
}
}
psA.on(topic, incMsg)
psA.subscribe(topic)
// await subscription change
await Promise.all([
new Promise(resolve => psB.once('pubsub:subscription-change', () => resolve(null)))
])
// await a cycle
await delay(1000)
psC.publish(topic, uint8ArrayFromString('hey'))
return defer.promise
})
})
describe('1 level tree', () => {