Skip to content

Commit

Permalink
Added websocket close event test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Leal authored and jcrugzz committed Dec 17, 2014
1 parent 2653786 commit 8bff3dd
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/lib-http-proxy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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);

});


})
});

0 comments on commit 8bff3dd

Please sign in to comment.