Skip to content

Proper websocket test fixes, after patching node-websocket-client #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 9, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions support/node-websocket-client/lib/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,13 @@ var WebSocket = function(url, proto, opts) {
return function(req, s, head) {
stream = s;

if (readyState == CLOSED) {
stream.end();
stream.destroy();
stream = undefined;
return;
}

stream.on('data', function(d) {
if (d.length <= 0) {
return;
Expand Down
1 change: 0 additions & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ client = function (port) {
*/

create = function (cl) {
console.log('');
var manager = io.listen(cl.port);
manager.set('client store expiration', 0);
return manager;
Expand Down
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