File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,8 @@ async function download (gyp, url) {
1111 Connection : 'keep-alive'
1212 } ,
1313 proxy : gyp . opts . proxy ,
14- noProxy : gyp . opts . noproxy
14+ noProxy : gyp . opts . noproxy ,
15+ retry : 3
1516 }
1617
1718 const cafile = gyp . opts . cafile
Original file line number Diff line number Diff line change @@ -153,6 +153,32 @@ describe('download', function () {
153153 assert . notStrictEqual ( cas [ 0 ] , cas [ 1 ] )
154154 } )
155155
156+ it ( 'download will retry on ECONNRESET' , async function ( ) {
157+ let requestCount = 0
158+ const server = http . createServer ( ( req , res ) => {
159+ requestCount ++
160+ if ( requestCount < 3 ) {
161+ req . socket . destroy ( )
162+ return
163+ }
164+ res . end ( 'ok' )
165+ } )
166+
167+ after ( ( ) => new Promise ( ( resolve ) => server . close ( resolve ) ) )
168+
169+ const host = 'localhost'
170+ await new Promise ( ( resolve ) => server . listen ( 0 , host , resolve ) )
171+ const { port } = server . address ( )
172+ const gyp = {
173+ opts : { } ,
174+ version : '42'
175+ }
176+ const url = `http://${ host } :${ port } `
177+ const res = await download ( gyp , url )
178+ assert . strictEqual ( await res . text ( ) , 'ok' )
179+ assert . ok ( requestCount >= 2 , `expected at least 2 requests but got ${ requestCount } ` )
180+ } )
181+
156182 // only run this test if we are running a version of Node with predictable version path behavior
157183
158184 it ( 'download headers (actual)' , async function ( ) {
You can’t perform that action at this time.
0 commit comments