-
Notifications
You must be signed in to change notification settings - Fork 58
fix: handle idle socket error #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
addb640
test: run on more node versions
fengmk2 f588a95
fix: handle idle socket error
fengmk2 ee67611
chore: use codecov
fengmk2 27a884e
refactor: make sure only one error listener
fengmk2 e541fdd
test: add appveyor ci build
fengmk2 2fbb3a7
test: add Circle ci
fengmk2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- '0.10' | ||
- '0.11' | ||
- '0.12' | ||
- 'iojs-1' | ||
script: "npm run test-travis" | ||
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls" | ||
- '4.3.2' | ||
- '4' | ||
- '5.3.0' | ||
- '5' | ||
script: 'npm run ci' | ||
after_script: 'npm run codecov' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
environment: | ||
global: | ||
npm_registry: https://registry.npmjs.com | ||
|
||
matrix: | ||
- nodejs_version: "0.10" | ||
- nodejs_version: "0.12" | ||
- nodejs_version: "4.3.2" | ||
- nodejs_version: "4" | ||
- nodejs_version: "5.3.0" | ||
- nodejs_version: "5" | ||
|
||
# Install scripts. (runs after repo cloning) | ||
install: | ||
# Get the latest stable version of Node.js or io.js | ||
- ps: Install-Product node $env:nodejs_version | ||
# install modules | ||
- npm i | ||
|
||
# Post-install test scripts. | ||
test_script: | ||
# Output useful info for debugging. | ||
- node --version | ||
- npm --version | ||
- npm run ci | ||
|
||
# Don't actually build. | ||
build: off |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
machine: | ||
node: | ||
version: '4' | ||
|
||
dependencies: | ||
override: | ||
- nvm ls | ||
|
||
test: | ||
override: | ||
- nvm i 0.10 && rm -rf node_modules && npm i && npm run ci && npm run codecov | ||
- nvm i 0.12 && rm -rf node_modules && npm i && npm run ci && npm run codecov | ||
- nvm i 4.3.2 && rm -rf node_modules && npm i && npm run ci && npm run codecov | ||
- nvm i 4 && rm -rf node_modules && npm i && npm run ci && npm run codecov | ||
- nvm i 5.3.0 && rm -rf node_modules && npm i && npm run ci && npm run codecov | ||
- nvm i 5 && rm -rf node_modules && npm i && npm run ci && npm run codecov | ||
|
||
# https://circleci.com/docs/language-nodejs | ||
# https://discuss.circleci.com/t/testing-multiple-versions-of-node/542 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,17 @@ | |
"description": "Missing keepalive http.Agent", | ||
"main": "index.js", | ||
"files": [ | ||
"index.js", "lib/" | ||
"index.js", | ||
"lib" | ||
], | ||
"scripts": { | ||
"test": "mocha -R spec -t 5000 -r should-http test/*.test.js", | ||
"test-cov": "node node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -t 5000 -r should-http test/*.test.js", | ||
"test-travis": "node node_modules/.bin/istanbul cover node_modules/.bin/_mocha --report lcovonly -- -t 5000 -r should-http test/*.test.js", | ||
"jshint": "jshint .", | ||
"autod": "autod -w --prefix '~' && npm run cnpm", | ||
"cnpm": "npm install --registry=https://registry.npm.taobao.org", | ||
"contributors": "contributors -f plain -o AUTHORS" | ||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- -t 5000 -r should-http test/*.test.js", | ||
"ci": "npm run lint && npm run test-cov", | ||
"lint": "jshint .", | ||
"autod": "autod -w --prefix '~'", | ||
"contributors": "contributors -f plain -o AUTHORS", | ||
"codecov": "npm i codecov && codecov" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
|
@@ -24,22 +25,25 @@ | |
}, | ||
"keywords": [ | ||
"http", | ||
"https", | ||
"agent", | ||
"keepalive" | ||
"keepalive", | ||
"agentkeepalive" | ||
], | ||
"dependencies": { | ||
|
||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"autod": "*", | ||
"contributors": "*", | ||
"istanbul": "*", | ||
"mocha": "*", | ||
"pedding": "~1.0.0", | ||
"should": "~4.0.4", | ||
"should-http": "~0.0.2" | ||
"pedding": "1", | ||
"should": "4", | ||
"should-http": "~0.0.2", | ||
"jshint": "^2.9.1" | ||
}, | ||
"engines": { | ||
"node": ">= 0.10.0" | ||
}, | ||
"engines": { "node": ">= 0.10.0" }, | ||
"author": "fengmk2 <[email protected]> (http://fengmk2.com)", | ||
"license": "MIT" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
/*! | ||
* agentkeepalive - test/agent.test.js | ||
* | ||
/** | ||
* Copyright(c) 2012 - 2013 fengmk2 <[email protected]> | ||
* Copyright(c) node-modules | ||
* MIT Licensed | ||
|
@@ -19,7 +17,7 @@ require('should-http'); | |
var pedding = require('pedding'); | ||
var Agent = require('../'); | ||
|
||
describe('agent.test.js', function () { | ||
describe('test/agent.test.js', function () { | ||
|
||
var agentkeepalive = new Agent({ | ||
keepAliveTimeout: 1000, | ||
|
@@ -810,4 +808,44 @@ describe('agent.test.js', function () { | |
}); | ||
}); | ||
|
||
describe('mock idle socket error', function() { | ||
it('should idle socket emit error event', function(done) { | ||
var agent = new Agent(); | ||
|
||
var options = { | ||
host: 'www.taobao.com', | ||
port: 80, | ||
path: '/', | ||
agent: agent | ||
}; | ||
|
||
var socketKey = agent.getName(options); | ||
var req = http.get(options, function(res) { | ||
var size = 0; | ||
res.on('data', function(chunk) { | ||
size += chunk.length; | ||
}); | ||
res.on('end', function() { | ||
size.should.above(0); | ||
Object.keys(agent.freeSockets).should.length(0); | ||
process.nextTick(function() { | ||
should.exist(agent.freeSockets[socketKey]); | ||
agent.freeSockets[socketKey].should.length(1); | ||
setTimeout(function() { | ||
// agent should catch idle socket error event | ||
agent.freeSockets[socketKey][0].emit('error', new Error('mock read ECONNRESET')); | ||
|
||
setTimeout(function() { | ||
// error socket should be destroy and remove | ||
Object.keys(agent.freeSockets).should.length(0); | ||
done(); | ||
}, 10); | ||
}, 10); | ||
}); | ||
}); | ||
res.resume(); | ||
}); | ||
req.on('error', done); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dead-horse fixed