File tree 2 files changed +63
-1
lines changed
2 files changed +63
-1
lines changed Original file line number Diff line number Diff line change @@ -1495,6 +1495,37 @@ describe('test/agent.test.js', () => {
1495
1495
assert ( Object . keys ( agentkeepalive . sockets ) . length === 1 ) ;
1496
1496
} ) ;
1497
1497
1498
+ describe ( 'request timeout > agent timeout' , ( ) => {
1499
+ it ( 'should use request timeout' , done => {
1500
+ const agent = new Agent ( {
1501
+ keepAlive : true ,
1502
+ timeout : 1000 ,
1503
+ } ) ;
1504
+ const req = http . get ( {
1505
+ agent,
1506
+ port,
1507
+ path : '/?timeout=20000' ,
1508
+ timeout : 1500 ,
1509
+ } , res => {
1510
+ console . error ( res . statusCode , res . headers ) ;
1511
+ assert . fail ( 'should not get res here' ) ;
1512
+ } ) ;
1513
+
1514
+ let isTimeout = false ;
1515
+ req . on ( 'timeout' , ( ) => {
1516
+ isTimeout = true ;
1517
+ req . abort ( ) ;
1518
+ } ) ;
1519
+ req . on ( 'error' , err => {
1520
+ assert ( isTimeout ) ;
1521
+ assert ( err ) ;
1522
+ assert ( err . message === 'socket hang up' ) ;
1523
+ assert ( err . code === 'ECONNRESET' ) ;
1524
+ done ( ) ;
1525
+ } ) ;
1526
+ } ) ;
1527
+ } ) ;
1528
+
1498
1529
describe ( 'keepAlive = false' , ( ) => {
1499
1530
it ( 'should close socket after request' , done => {
1500
1531
const name = 'localhost:' + port + ':' ;
Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ const urlparse = require('url').parse;
5
5
const fs = require ( 'fs' ) ;
6
6
const assert = require ( 'assert' ) ;
7
7
const HttpsAgent = require ( '..' ) . HttpsAgent ;
8
- // const HttpsAgent = https.Agent;
9
8
10
9
describe ( 'test/https_agent.test.js' , ( ) => {
11
10
let app = null ;
@@ -219,4 +218,36 @@ describe('test/https_agent.test.js', () => {
219
218
} ) ;
220
219
} ) ;
221
220
} ) ;
221
+
222
+ describe ( 'request timeout > agent timeout' , ( ) => {
223
+ it ( 'should use request timeout' , done => {
224
+ const agent = new HttpsAgent ( {
225
+ keepAlive : true ,
226
+ timeout : 2000 ,
227
+ } ) ;
228
+ const req = https . get ( {
229
+ agent,
230
+ port,
231
+ path : '/?timeout=20000' ,
232
+ timeout : 2500 ,
233
+ ca : fs . readFileSync ( __dirname + '/fixtures/ca.pem' ) ,
234
+ } , res => {
235
+ console . error ( res . statusCode , res . headers ) ;
236
+ assert . fail ( 'should not get res here' ) ;
237
+ } ) ;
238
+
239
+ let isTimeout = false ;
240
+ req . on ( 'timeout' , ( ) => {
241
+ isTimeout = true ;
242
+ req . abort ( ) ;
243
+ } ) ;
244
+ req . on ( 'error' , err => {
245
+ assert ( isTimeout ) ;
246
+ assert ( err ) ;
247
+ assert ( err . message === 'socket hang up' ) ;
248
+ assert ( err . code === 'ECONNRESET' ) ;
249
+ done ( ) ;
250
+ } ) ;
251
+ } ) ;
252
+ } ) ;
222
253
} ) ;
You can’t perform that action at this time.
0 commit comments