forked from daguej/node-proxywrap
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
José Moreira
committed
Jan 18, 2016
1 parent
3a0ccc8
commit 8fb1410
Showing
3 changed files
with
150 additions
and
133 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 |
---|---|---|
@@ -1,88 +1,106 @@ | ||
'use strict'; | ||
|
||
/* related to issue https://github.com/findhit/proxywrap/issues/15 */ | ||
var http = require('http') | ||
var assert = require('assert') | ||
var net = require('net') | ||
var exec = require('child_process').exec | ||
var http = require( 'http' ) | ||
var assert = require( 'assert' ) | ||
var net = require( 'net' ) | ||
var exec = require( 'child_process' ).exec | ||
var child | ||
var proxyWrap = require('../..') | ||
var proxyWrap = require( '../..' ) | ||
|
||
function findCloseWaitConnections(port, callback) { | ||
function findCloseWaitConnections ( port, callback ) { | ||
var child = exec('netstat -tonp | grep 8000 | grep CLOSE_WAIT', | ||
function (err, stdout, stderr) { | ||
if (err) { | ||
return callback(err); | ||
function ( err, stdout, stderr ) { | ||
if ( err ) { | ||
return callback(err) | ||
} | ||
return callback(null, stdout); | ||
}); | ||
return callback(null, stdout) | ||
}) | ||
} | ||
|
||
function reproduce(proxyWrapConf, callback) { | ||
var socket, server, port, proxiedHttp; | ||
if (!callback) { | ||
callback = proxyWrapConf; | ||
proxyWrapConf = null; | ||
function reproduce ( proxyWrapConf, callback ) { | ||
var socket, server, port, proxiedHttp | ||
if ( ! callback ) { | ||
callback = proxyWrapConf | ||
proxyWrapConf = null | ||
} | ||
|
||
proxiedHttp = proxyWrap.proxy(http, proxyWrapConf); | ||
proxiedHttp = proxyWrap.proxy( http, proxyWrapConf ) | ||
|
||
server = proxiedHttp | ||
.createServer(function handler ( req, res) { | ||
throw new Error('For this test socket should not call #write()') | ||
}) | ||
.listen(function ( err ) { | ||
|
||
server = proxiedHttp.createServer(function handler(req, res) { | ||
throw new Error('For this test socket should not call #write()'); | ||
}).listen(function (err) { | ||
if (err) { | ||
return done(err); | ||
return done(err) | ||
} | ||
port = this.address().port; | ||
socket = net.connect({ | ||
port: port | ||
}, function () { | ||
socket.end(); | ||
}); | ||
socket.on('end', function () { | ||
return callback(null, server); | ||
}); | ||
}); | ||
|
||
port = this.address().port | ||
|
||
socket = net.connect( | ||
{ | ||
port: port | ||
}, | ||
function () { | ||
socket.end() | ||
} | ||
) | ||
|
||
socket.on( 'end', function () { | ||
return callback( null, server ) | ||
}) | ||
}) | ||
} | ||
describe('Sockets closed before any write #15', function () { | ||
describe('On strict mode', function () { | ||
var port, server; | ||
before(function (done) { | ||
reproduce(function (err, _server) { | ||
server = _server; | ||
port = server.address().port; | ||
return done(); | ||
}); | ||
}); | ||
|
||
describe( 'Sockets closed before any write #15', function () { | ||
describe( 'On strict mode', function () { | ||
var port, server | ||
|
||
before(function ( done ) { | ||
reproduce(function ( err, _server ) { | ||
server = _server | ||
port = server.address().port | ||
done() | ||
}) | ||
}) | ||
|
||
after(function () { | ||
server.close(); | ||
}); | ||
it('should be restored', function (done) { | ||
findCloseWaitConnections(port, function (err, stdout) { | ||
assert(!stdout); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
describe('On non-strict mode', function () { | ||
var port, server; | ||
before(function (done) { | ||
reproduce({ | ||
strict: false | ||
}, function (err, _server) { | ||
server = _server; | ||
port = server.address().port; | ||
return done(); | ||
}); | ||
}); | ||
server.close() | ||
}) | ||
|
||
it( 'should be restored', function ( done ) { | ||
findCloseWaitConnections( port, function ( err, stdout ) { | ||
assert( ! stdout ) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
describe( 'On non-strict mode', function () { | ||
var port, server | ||
|
||
before(function ( done ) { | ||
reproduce( | ||
{ | ||
strict: false | ||
}, | ||
function ( err, _server ) { | ||
server = _server | ||
port = server.address().port | ||
done() | ||
} | ||
) | ||
}) | ||
|
||
after(function () { | ||
server.close(); | ||
}); | ||
it('should be restored', function (done) { | ||
findCloseWaitConnections(port, function (err, stdout) { | ||
assert(!stdout); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
server.close() | ||
}) | ||
|
||
it( 'should be restored', function ( done ) { | ||
findCloseWaitConnections( port, function ( err, stdout ) { | ||
assert( ! stdout ) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.