-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: should autofix socket timeout by request.timeout (#300)
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,42 @@ | ||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
var Agent = require('agentkeepalive'); | ||
var urllib = require('..'); | ||
var server = require('./fixtures/server'); | ||
|
||
describe('test/request-timeout.test.js', function() { | ||
var host = 'http://127.0.0.1:'; | ||
var port; | ||
|
||
before(function(done) { | ||
server.listen(0, function() { | ||
port = server.address().port; | ||
host += port; | ||
done(); | ||
}); | ||
}); | ||
|
||
after(function(done) { | ||
setTimeout(function() { | ||
server.close(); | ||
done(); | ||
}, 1000); | ||
}); | ||
|
||
it('should work on request timeout bigger than agent timeout', function(done) { | ||
var agent = new Agent({ | ||
timeout: 1000, | ||
}); | ||
var url = host + '/response_timeout_10s'; | ||
urllib.request(url, { | ||
timeout: 1500, | ||
agent: agent, | ||
}, function(err) { | ||
assert(err); | ||
assert(err.name === 'ResponseTimeoutError'); | ||
assert(err.message.indexOf('Response timeout for 1500ms') === 0); | ||
done(); | ||
}); | ||
}); | ||
}); |