Skip to content
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

Improve test-timeout reliability #2414

Merged
merged 1 commit into from Oct 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions tests/test-timeout.js
Expand Up @@ -122,16 +122,30 @@ tape('float timeout', function(t) { // should be rounded by setTimeout anyway
})
})

tape('connect timeout', function(t) {
// We need a destination that will not immediately return a TCP Reset
// packet. StackOverflow suggests this host:
// https://stackoverflow.com/a/904609/329700
var tarpitHost = 'http://10.255.255.1'
// We need a destination that will not immediately return a TCP Reset
// packet. StackOverflow suggests these hosts:
// (https://stackoverflow.com/a/904609/329700)
var nonRoutable = [
'10.255.255.1',
'10.0.0.0',
'192.168.0.0',
'192.168.255.255',
'172.16.0.0',
'172.31.255.255'
]
tape('connect timeout', function tryConnect(t) {
var tarpitHost = 'http://' + nonRoutable.shift()
var shouldConnectTimeout = {
url: tarpitHost + '/timeout',
timeout: 100
}
request(shouldConnectTimeout, function(err) {
if (err.code === 'ENETUNREACH' && nonRoutable.length) {
// With some network configurations, some addresses will be reported as
// unreachable immediately (before the timeout occurs). In those cases,
// try other non-routable addresses before giving up.
return tryConnect(t)
}
checkErrCode(t, err)
t.ok(err.connect === true, 'Connect Timeout Error should set \'connect\' property to true')
t.end()
Expand Down