commit 3ef63ac15e3ba875c8953f9f33619bcb36cdddd1
Author: Tom Hughes <tom@compton.nu>
Date: Thu Oct 8 21:34:50 2015 +0100
Patch out tests that rely on internet access
diff --git a/test/agent.test.js b/test/agent.test.js
index 33a3908..8d51bd3 100644
--- a/test/agent.test.js
+++ b/test/agent.test.js
@@ -809,51 +809,6 @@ describe('test/agent.test.js', () => {
});
});
- it('should timeout and remove free socket', done => {
- done = pedding(2, done);
- const _keepaliveAgent = new Agent({
- maxSockets: 1,
- maxFreeSockets: 1,
- keepAliveTimeout: 1000,
- });
-
- const options = {
- hostname: 'registry.npmjs.org',
- port: 80,
- path: '/',
- method: 'GET',
- agent: _keepaliveAgent,
- };
-
- let index = 0;
- const getRequest = () => {
- const currentIndex = index++;
- const req = http.request(options, res => {
- let size = 0;
- res.on('data', chunk => {
- size += chunk.length;
- });
- res.on('end', () => {
- console.log('#%d req end, size: %d', currentIndex, size);
- done();
- });
- });
- req.on('error', done);
- return req;
- };
-
- const req = getRequest();
- // Get a reference to the socket.
- req.on('socket', sock => {
- // Listen to timeout and send another request immediately.
- sock.on('timeout', () => {
- console.log('socket:%s timeout', sock._host);
- getRequest().end();
- });
- });
- req.end();
- });
-
it('should not open more sockets than maxSockets when request success', done => {
done = pedding(3, done);
const name = 'localhost:' + port + ':';
@@ -1002,48 +957,6 @@ describe('test/agent.test.js', () => {
});
});
- describe('mock idle socket error', () => {
- it('should idle socket emit error event', done => {
- const agent = new Agent();
-
- const options = {
- host: 'registry.npmjs.org',
- port: 80,
- path: '/',
- agent,
- };
-
- const socketKey = agent.getName(options);
- const req = http.get(options, res => {
- let size = 0;
- assert(res.headers.connection === 'keep-alive');
- res.on('data', chunk => {
- size += chunk.length;
- });
- res.on('end', () => {
- assert(size > 0);
- assert(Object.keys(agent.sockets).length === 1);
- assert(Object.keys(agent.freeSockets).length === 0);
- process.nextTick(() => {
- assert(agent.freeSockets[socketKey].length === 1);
- setTimeout(() => {
- // agent should catch idle socket error event
- agent.freeSockets[socketKey][0].emit('error', new Error('mock read ECONNRESET'));
-
- setTimeout(() => {
- // error socket should be destroy and remove
- assert(Object.keys(agent.freeSockets).length === 0);
- done();
- }, 10);
- }, 10);
- });
- });
- res.resume();
- });
- req.on('error', done);
- });
- });
-
describe('options.socketActiveTTL', () => {
it('should expire active socket when it is out of ttl', done => {
const name = 'localhost:' + port + ':';