Skip to content

Commit

Permalink
properly cleaned up async websocket / flashsocket tests, after patchi…
Browse files Browse the repository at this point in the history
…ng node-websocket-client
  • Loading branch information
einaros committed Oct 8, 2011
1 parent 08568ee commit b3df283
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 43 deletions.
7 changes: 6 additions & 1 deletion test/transports.flashsocket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,18 @@ module.exports = {
'flashsocket identifies as flashsocket': function (done) {
var cl = client(++ports)
, io = create(cl)
, messages = 0
, ws;

io.set('transports', ['flashsocket']);
io.sockets.on('connection', function (socket) {
socket.manager.transports[socket.id].name.should.equal('flashsocket');
ws.finishClose();
cl.end();
io.flashPolicyServer.close();
io.server.close();
done();
});

cl.handshake(function (sid) {
ws = websocket(cl, sid, 'flashsocket');
});
Expand Down
77 changes: 35 additions & 42 deletions test/transports.websocket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,24 @@ var sio = require('socket.io')
*/

module.exports = {

'websocket identifies as websocket': function (done) {
var cl = client(++ports)
, io = create(cl)
, ws;

io.set('transports', ['websocket']);
io.sockets.on('connection', function (socket) {
socket.manager.transports[socket.id].name.should.equal('websocket');
ws.finishClose();
cl.end();
io.server.close();
done();
});
cl.handshake(function (sid) {
ws = websocket(cl, sid);
});
},

'default websocket draft parser is used for unknown sec-websocket-version': function (done) {
var cl = client(++ports)
, io = create(cl)
Expand All @@ -28,17 +45,10 @@ module.exports = {
io.set('transports', ['websocket']);
io.sockets.on('connection', function (socket) {
socket.manager.transports[socket.id].protocolVersion.should.equal('hixie-76');

socket.on('disconnect', function () {
setTimeout(function () {
ws.finishClose();
cl.end();
io.server.close();
done();
}, 10);
});

socket.disconnect();
ws.finishClose();
cl.end();
io.server.close();
done();
});

cl.handshake(function (sid) {
Expand All @@ -48,22 +58,14 @@ module.exports = {

'hybi-07-12 websocket draft parser is used for sec-websocket-version: 8': function (done) {
var cl = client(++ports)
, io = create(cl)
, ws;
, io = create(cl);

io.set('transports', ['websocket']);
io.sockets.on('connection', function (socket) {
socket.manager.transports[socket.id].protocolVersion.should.equal('07-12');

socket.on('disconnect', function () {
setTimeout(function () {
cl.end();
io.server.close();
done();
}, 10);
});

socket.disconnect();
cl.end();
io.server.close();
done();
});

var headers = {
Expand All @@ -87,16 +89,9 @@ module.exports = {

io.sockets.on('connection', function (socket) {
socket.manager.transports[socket.id].protocolVersion.should.equal('16');

socket.on('disconnect', function () {
setTimeout(function () {
cl.end();
io.server.close();
done();
}, 10);
});

socket.disconnect();
cl.end();
io.server.close();
done();
});

var headers = {
Expand Down Expand Up @@ -131,10 +126,9 @@ module.exports = {
var sid = data.split(':')[0];
var url = '/socket.io/' + sio.protocol + '/websocket/' + sid;
cl.get(url, {headers: headers}, function (res, data) {});
res.client.onend = function() {
io.server.close();
done();
}
cl.end();
io.server.close();
done();
});
},

Expand All @@ -157,10 +151,9 @@ module.exports = {
var sid = data.split(':')[0];
var url = '/socket.io/' + sio.protocol + '/websocket/' + sid;
cl.get(url, {headers: headers}, function (res, data) {});
res.client.onend = function() {
io.server.close();
done();
}
cl.end();
io.server.close();
done();
});
},

Expand Down

0 comments on commit b3df283

Please sign in to comment.