Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
chore: tweak test
  • Loading branch information
wemeetagain committed Jun 18, 2020
commit 5c6df19b290b145ba78c74c81e61872fc5959c7b
17 changes: 8 additions & 9 deletions test/gossip.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('gossip', () => {
nodeA.log.restore()
})

it('should send piggyback gossip into other sent messages', async function () {
it('should send piggyback control into other sent messages', async function () {
this.timeout(10000)
const nodeA = nodes[0]
const topic = 'Z'
Expand All @@ -79,21 +79,20 @@ describe('gossip', () => {
const nodeB = nodes.find((n) => n.peerId.toB58String() === peerB.id.toB58String())

// set spy
sinon.spy(nodeB, 'log')
sinon.spy(nodeA, '_piggybackControl')

// manually add control message to be sent to peerB
nodeA.control.set(peerB, { graft: [{ topicID: topic }] })
const graft = { graft: [{ topicID: topic }] }
nodeA.control.set(peerB, graft)

await nodeA.publish(topic, Buffer.from('hey'))

await new Promise((resolve) => nodeA.once('gossipsub:heartbeat', resolve))
expect(nodeB.log.callCount).to.be.gt(1)
expect(nodeA._piggybackControl.callCount).to.be.equal(1)
// expect control message to be sent alongside published message
const call = nodeB.log.getCalls().find((call) => call.args[0] === 'GRAFT: Add mesh link from %s in %s')
expect(call).to.not.equal(undefined)
expect(call.args[1]).to.equal(nodeA.peerId.toB58String())
const call = nodeA._piggybackControl.getCalls()[0]
expect(call.args[2].graft).to.deep.equal(graft.graft)

// unset spy
nodeB.log.restore()
nodeA._piggybackControl.restore()
})
})