This repository was archived by the owner on Jun 26, 2023. It is now read-only.
File tree 2 files changed +19
-0
lines changed
2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 46
46
"libp2p-tcp" : " ^0.14.1" ,
47
47
"multiaddr" : " ^7.1.0" ,
48
48
"p-limit" : " ^2.2.1" ,
49
+ "p-wait-for" : " ^3.1.0" ,
49
50
"peer-id" : " ^0.13.3" ,
50
51
"sinon" : " ^7.5.0" ,
51
52
"streaming-iterables" : " ^4.1.0"
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ const expect = chai.expect
8
8
chai . use ( dirtyChai )
9
9
const sinon = require ( 'sinon' )
10
10
11
+ const pWaitFor = require ( 'p-wait-for' )
11
12
const pipe = require ( 'it-pipe' )
12
13
const { isValidTick } = require ( './utils' )
13
14
@@ -92,6 +93,23 @@ module.exports = (common) => {
92
93
expect ( upgradeSpy . callCount ) . to . equal ( 2 )
93
94
} )
94
95
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
+
95
113
describe ( 'events' , ( ) => {
96
114
it ( 'connection' , ( done ) => {
97
115
const upgradeSpy = sinon . spy ( upgrader , 'upgradeInbound' )
You can’t perform that action at this time.
0 commit comments