mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-06-13 03:41:35 +00:00
fix: transport should not handle connection if upgradeInbound throws (#16)
* fix: transport should not handle connection if upgradeInbound throws * chore: address review
This commit is contained in:
@ -8,6 +8,7 @@ const expect = chai.expect
|
||||
chai.use(dirtyChai)
|
||||
const sinon = require('sinon')
|
||||
|
||||
const pWaitFor = require('p-wait-for')
|
||||
const pipe = require('it-pipe')
|
||||
const { isValidTick } = require('./utils')
|
||||
|
||||
@ -92,6 +93,23 @@ module.exports = (common) => {
|
||||
expect(upgradeSpy.callCount).to.equal(2)
|
||||
})
|
||||
|
||||
it('should not handle connection if upgradeInbound throws', async () => {
|
||||
sinon.stub(upgrader, 'upgradeInbound').throws()
|
||||
|
||||
const listener = transport.createListener(() => {
|
||||
throw new Error('should not handle the connection if upgradeInbound throws')
|
||||
})
|
||||
|
||||
// Listen
|
||||
await listener.listen(addrs[0])
|
||||
|
||||
// Create a connection to the listener
|
||||
const socket = await transport.dial(addrs[0])
|
||||
|
||||
await pWaitFor(() => typeof socket.timeline.close === 'number')
|
||||
await listener.close()
|
||||
})
|
||||
|
||||
describe('events', () => {
|
||||
it('connection', (done) => {
|
||||
const upgradeSpy = sinon.spy(upgrader, 'upgradeInbound')
|
||||
|
Reference in New Issue
Block a user