File tree Expand file tree Collapse file tree 3 files changed +34
-6
lines changed
Expand file tree Collapse file tree 3 files changed +34
-6
lines changed Original file line number Diff line number Diff line change 44 * Module dependencies.
55 */
66const methods = require ( 'methods' ) ;
7- const http = require ( 'http' ) ;
87let http2 ;
98try {
109 http2 = require ( 'http2' ) ; // eslint-disable-line global-require
@@ -32,15 +31,12 @@ module.exports = function(app, options = {}) {
3231 'supertest: this version of Node.js does not support http2'
3332 ) ;
3433 }
35- app = http2 . createServer ( app ) ; // eslint-disable-line no-param-reassign
36- } else {
37- app = http . createServer ( app ) ; // eslint-disable-line no-param-reassign
3834 }
3935 }
4036
4137 methods . forEach ( function ( method ) {
4238 obj [ method ] = function ( url ) {
43- var test = new Test ( app , method , url ) ;
39+ var test = new Test ( app , method , url , options . http2 ) ;
4440 if ( options . http2 ) {
4541 test . http2 ( ) ;
4642 }
Original file line number Diff line number Diff line change 55 */
66
77const { inspect } = require ( 'util' ) ;
8+ const http = require ( 'http' ) ;
89const { STATUS_CODES } = require ( 'http' ) ;
910const { Server } = require ( 'tls' ) ;
1011const { deepStrictEqual } = require ( 'assert' ) ;
1112const { Request } = require ( 'superagent' ) ;
13+ let http2 ;
14+ try {
15+ http2 = require ( 'http2' ) ; // eslint-disable-line global-require
16+ } catch ( _ ) {
17+ // eslint-disable-line no-empty
18+ }
1219
1320/** @typedef {import('superagent').Response } Response */
1421
@@ -22,9 +29,17 @@ class Test extends Request {
2229 * @param {String } path
2330 * @api public
2431 */
25- constructor ( app , method , path ) {
32+ constructor ( app , method , path , optHttp2 ) {
2633 super ( method . toUpperCase ( ) , path ) ;
2734
35+ if ( typeof app === 'function' ) {
36+ if ( optHttp2 ) {
37+ app = http2 . createServer ( app ) ; // eslint-disable-line no-param-reassign
38+ } else {
39+ app = http . createServer ( app ) ; // eslint-disable-line no-param-reassign
40+ }
41+ }
42+
2843 this . redirects ( 0 ) ;
2944 this . buffer ( ) ;
3045 this . app = app ;
Original file line number Diff line number Diff line change @@ -79,6 +79,23 @@ describe('request(app)', function () {
7979 } ) ;
8080 } ) ;
8181
82+ it ( 'should not ECONNRESET on multiple simultaneous tests' , function ( done ) {
83+ const app = express ( ) ;
84+
85+ app . get ( '/' , function ( req , res ) {
86+ res . send ( 'hey' ) ;
87+ } ) ;
88+
89+ const test = request ( app ) ;
90+
91+ const requestCount = 10 ;
92+
93+ const requests = [ ] ;
94+ for ( let i = 0 ; i < requestCount ; i += 1 ) requests . push ( test . get ( '/' ) ) ;
95+
96+ global . Promise . all ( requests ) . then ( ( ) => done ( ) , done ) ;
97+ } ) ;
98+
8299 it ( 'should work with an active server' , function ( done ) {
83100 const app = express ( ) ;
84101 let server ;
You can’t perform that action at this time.
0 commit comments