Added websocket close event test

This commit is contained in:
Jorge Leal 2014-12-11 15:11:21 +01:00 committed by Jarrett Cruger
parent 26537866b3
commit 8bff3ddc12

View File

@ -336,6 +336,7 @@ describe('lib/http-proxy.js', function() {
});
});
it('should proxy a socket.io stream', function (done) {
var ports = { source: gen.port, proxy: gen.port },
proxy = httpProxy.createProxyServer({
@ -370,5 +371,36 @@ describe('lib/http-proxy.js', function() {
});
})
});
it('should emit close event when socket.io client disconnects', function (done) {
var ports = { source: gen.port, proxy: gen.port };
var proxy = httpProxy.createProxyServer({
target: 'ws://127.0.0.1:' + ports.source,
ws: true
});
proxyServer = proxy.listen(ports.proxy);
var server = http.createServer();
destiny = io.listen(server);
function startSocketIo() {
var client = ioClient.connect('ws://127.0.0.1:' + ports.proxy);
client.on('connect', function () {
client.disconnect();
});
}
proxyServer.on('close', function() {
proxyServer.close();
server.close();
done();
});
server.listen(ports.source);
server.on('listening', startSocketIo);
});
})
});