Skip to content

Commit 8bff3dd

Browse files
Jorge Lealjcrugzz
Jorge Leal
authored andcommitted
Added websocket close event test
1 parent 2653786 commit 8bff3dd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/lib-http-proxy-test.js

+32
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ describe('lib/http-proxy.js', function() {
336336
});
337337
});
338338

339+
339340
it('should proxy a socket.io stream', function (done) {
340341
var ports = { source: gen.port, proxy: gen.port },
341342
proxy = httpProxy.createProxyServer({
@@ -370,5 +371,36 @@ describe('lib/http-proxy.js', function() {
370371
});
371372
})
372373
});
374+
375+
376+
it('should emit close event when socket.io client disconnects', function (done) {
377+
var ports = { source: gen.port, proxy: gen.port };
378+
var proxy = httpProxy.createProxyServer({
379+
target: 'ws://127.0.0.1:' + ports.source,
380+
ws: true
381+
});
382+
proxyServer = proxy.listen(ports.proxy);
383+
var server = http.createServer();
384+
destiny = io.listen(server);
385+
386+
function startSocketIo() {
387+
var client = ioClient.connect('ws://127.0.0.1:' + ports.proxy);
388+
client.on('connect', function () {
389+
client.disconnect();
390+
});
391+
}
392+
393+
proxyServer.on('close', function() {
394+
proxyServer.close();
395+
server.close();
396+
done();
397+
});
398+
399+
server.listen(ports.source);
400+
server.on('listening', startSocketIo);
401+
402+
});
403+
404+
373405
})
374406
});

0 commit comments

Comments
 (0)