This repository was archived by the owner on Jun 26, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 4646 "libp2p-tcp" : " ^0.14.1" ,
4747 "multiaddr" : " ^7.1.0" ,
4848 "p-limit" : " ^2.2.1" ,
49+ "p-wait-for" : " ^3.1.0" ,
4950 "peer-id" : " ^0.13.3" ,
5051 "sinon" : " ^7.5.0" ,
5152 "streaming-iterables" : " ^4.1.0"
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ const expect = chai.expect
88chai . use ( dirtyChai )
99const sinon = require ( 'sinon' )
1010
11+ const pWaitFor = require ( 'p-wait-for' )
1112const pipe = require ( 'it-pipe' )
1213const { isValidTick } = require ( './utils' )
1314
@@ -92,6 +93,23 @@ module.exports = (common) => {
9293 expect ( upgradeSpy . callCount ) . to . equal ( 2 )
9394 } )
9495
96+ it ( 'should not handle connection if upgradeInbound throws' , async ( ) => {
97+ sinon . stub ( upgrader , 'upgradeInbound' ) . throws ( )
98+
99+ const listener = transport . createListener ( ( ) => {
100+ throw new Error ( 'should not handle the connection if upgradeInbound throws' )
101+ } )
102+
103+ // Listen
104+ await listener . listen ( addrs [ 0 ] )
105+
106+ // Create a connection to the listener
107+ const socket = await transport . dial ( addrs [ 0 ] )
108+
109+ await pWaitFor ( ( ) => typeof socket . timeline . close === 'number' )
110+ await listener . close ( )
111+ } )
112+
95113 describe ( 'events' , ( ) => {
96114 it ( 'connection' , ( done ) => {
97115 const upgradeSpy = sinon . spy ( upgrader , 'upgradeInbound' )
You can’t perform that action at this time.
0 commit comments