2019-01-14 09:14:13 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { expectsError, mustCall } = require('../common');
|
2019-01-31 19:46:18 +01:00
|
|
|
const { Agent, get, createServer } = require('http');
|
2019-01-14 09:14:13 +01:00
|
|
|
|
|
|
|
// Test that the `'timeout'` event is emitted on the `ClientRequest` instance
|
|
|
|
// when the socket timeout set via the `timeout` option of the `Agent` expires.
|
|
|
|
|
2019-01-31 19:46:18 +01:00
|
|
|
const server = createServer(mustCall(() => {
|
|
|
|
// Never respond.
|
2019-01-14 09:14:13 +01:00
|
|
|
}));
|
|
|
|
|
2019-01-31 19:46:18 +01:00
|
|
|
server.listen(() => {
|
|
|
|
const request = get({
|
|
|
|
agent: new Agent({ timeout: 500 }),
|
|
|
|
port: server.address().port
|
|
|
|
});
|
|
|
|
|
|
|
|
request.on('error', expectsError({
|
|
|
|
type: Error,
|
|
|
|
code: 'ECONNRESET',
|
|
|
|
message: 'socket hang up'
|
|
|
|
}));
|
|
|
|
|
|
|
|
request.on('timeout', mustCall(() => {
|
|
|
|
request.abort();
|
|
|
|
server.close();
|
|
|
|
}));
|
|
|
|
});
|