Skip to content

Commit

Permalink
Added callback to io.listen.
Browse files Browse the repository at this point in the history
Removed race condition in websocket room tests (for real this time)
  • Loading branch information
rauchg committed Jun 12, 2011
1 parent 7d2efd9 commit b9ab031
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
9 changes: 7 additions & 2 deletions lib/socket.io.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ exports.clientVersion = client.version;
* @api public
*/

exports.listen = function (server, options) {
exports.listen = function (server, options, fn) {
if ('function' == typeof options) {
fn = options;
options = {};
}

if ('undefined' == typeof server) {
// create a server that listens on port 80
server = 80;
Expand All @@ -58,7 +63,7 @@ exports.listen = function (server, options) {
res.end('Welcome to socket.io.');
});

server.listen(port);
server.listen(port, fn);
}

// otherwise assume a http/s server
Expand Down
49 changes: 43 additions & 6 deletions test/transports.websocket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,12 @@ module.exports = {
});

messages++;
ws1.finishClose();
}
});

setTimeout(function () {
ws1.finishClose();
}, 50);
});

cl2.handshake(function (sid) {
Expand All @@ -748,9 +751,12 @@ module.exports = {
});

messages++;
ws2.finishClose();
}
});

setTimeout(function () {
ws2.finishClose();
}, 50);
});

cl3.handshake(function (sid) {
Expand All @@ -760,6 +766,12 @@ module.exports = {
msg.type.should.eql('connect');
ws3.connected = true;
} else {
msg.should.eql({
type: 'message'
, data: 'hahaha'
, endpoint: ''
});

messages++;
}
});
Expand Down Expand Up @@ -829,9 +841,12 @@ module.exports = {
});

messages++;
ws1.finishClose();
}
});

setTimeout(function () {
ws1.finishClose();
}, 50);
});

cl2.handshake(function (sid) {
Expand All @@ -848,9 +863,12 @@ module.exports = {
});

messages++;
ws2.finishClose();
}
});

setTimeout(function () {
ws2.finishClose();
}, 50);
});

cl3.handshake(function (sid) {
Expand All @@ -860,6 +878,12 @@ module.exports = {
msg.type.should.eql('connect');
ws3.connected = true;
} else {
msg.should.eql({
type: 'json'
, data: 123
, endpoint: ''
});

messages++;
}
});
Expand Down Expand Up @@ -930,9 +954,12 @@ module.exports = {
});

messages++;
ws1.finishClose();
}
});

setTimeout(function () {
ws1.finishClose();
}, 50);
});

cl2.handshake(function (sid) {
Expand All @@ -950,9 +977,12 @@ module.exports = {
});

messages++;
ws2.finishClose();
}
});

setTimeout(function () {
ws2.finishClose();
}, 50);
});

cl3.handshake(function (sid) {
Expand All @@ -962,6 +992,13 @@ module.exports = {
msg.type.should.eql('connect');
ws3.connected = true;
} else {
msg.should.eql({
type: 'event'
, name: 'locki'
, args: []
, endpoint: ''
});

messages++;
}
});
Expand Down

0 comments on commit b9ab031

Please sign in to comment.