Skip to content

Commit

Permalink
chore: tweak test
Browse files Browse the repository at this point in the history
  • Loading branch information
wemeetagain committed Jun 18, 2020
1 parent 796a117 commit d71c258
Showing 1 changed file with 8 additions and 9 deletions.
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()
})
})

0 comments on commit d71c258

Please sign in to comment.