File tree 3 files changed +35
-2
lines changed
3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 58
58
"lodash" : " ^4.17.15" ,
59
59
"mocha" : " ^6.2.1" ,
60
60
"p-times" : " ^2.1.0" ,
61
+ "p-wait-for" : " ^3.1.0" ,
61
62
"promisify-es6" : " ^1.0.3" ,
62
63
"sinon" : " ^7.5.0"
63
64
},
Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ class BasicPubSub extends Pubsub {
98
98
* @override
99
99
* @param {string } idB58Str peer id string in base58
100
100
* @param {Connection } conn connection
101
- * @param {PeerInfo } peer peer info
101
+ * @param {Peer } peer PubSub peer
102
102
* @returns {void }
103
103
*
104
104
*/
@@ -117,7 +117,7 @@ class BasicPubSub extends Pubsub {
117
117
}
118
118
)
119
119
} catch ( err ) {
120
- this . _onPeerDisconnected ( peer , err )
120
+ this . _onPeerDisconnected ( peer . info , err )
121
121
}
122
122
}
123
123
Original file line number Diff line number Diff line change @@ -6,10 +6,12 @@ const chai = require('chai')
6
6
chai . use ( require ( 'dirty-chai' ) )
7
7
const expect = chai . expect
8
8
const sinon = require ( 'sinon' )
9
+ const pWaitFor = require ( 'p-wait-for' )
9
10
10
11
const { utils } = require ( 'libp2p-pubsub' )
11
12
const {
12
13
createGossipsub,
14
+ createPeerInfo,
13
15
mockRegistrar
14
16
} = require ( './utils' )
15
17
@@ -120,4 +122,34 @@ describe('Pubsub', () => {
120
122
} , 500 ) )
121
123
} )
122
124
} )
125
+
126
+ describe ( 'process' , ( ) => {
127
+ it ( 'should disconnect peer on stream error' , async ( ) => {
128
+ sinon . spy ( gossipsub , '_onPeerDisconnected' )
129
+
130
+ const peerInfo = await createPeerInfo ( )
131
+ const mockConn = {
132
+ newStream ( ) {
133
+ return {
134
+ stream : {
135
+ sink : async source => {
136
+ for await ( const _ of source ) { // eslint-disable-line no-unused-vars
137
+ // mock stream just swallows any data sent
138
+ }
139
+ } ,
140
+ source : ( async function * ( ) { // eslint-disable-line require-yield
141
+ // throw in a bit
142
+ await new Promise ( resolve => setTimeout ( resolve , 100 ) )
143
+ throw new Error ( 'boom' )
144
+ } ) ( )
145
+ }
146
+ }
147
+ }
148
+ }
149
+
150
+ gossipsub . _onPeerConnected ( peerInfo , mockConn )
151
+
152
+ await pWaitFor ( ( ) => gossipsub . _onPeerDisconnected . calledWith ( peerInfo ) , { timeout : 1000 } )
153
+ } )
154
+ } )
123
155
} )
You can’t perform that action at this time.
0 commit comments