Skip to content

Commit

Permalink
resolve race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
einaros committed Oct 25, 2011
1 parent 25f9743 commit 57b0ce7
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions test/namespace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ module.exports = {

io.of('a')
.on('connection', function (socket){
if (connect < 2) {
return;
}
socket.broadcast.emit('b', 'test');
socket.broadcast.json.emit('json', {foo:'bar'});
socket.broadcast.send('foo');
Expand All @@ -163,7 +166,6 @@ module.exports = {
connect.should.equal(2);
message.should.equal(1);
events.should.equal(2);

cl.end();
ws1.finishClose();
ws2.finishClose();
Expand All @@ -173,16 +175,19 @@ module.exports = {

cl.handshake(function (sid) {
ws1 = websocket(cl, sid);

ws1.on('open', function() {
ws1.packet({
type: 'connect'
, endpoint: 'a'
});
});

ws1.on('message', function (data) {
if (data.type === 'connect') {
if (connect == 0) {
cl.handshake(function (sid) {
ws2 = websocket(cl, sid);
ws2.on('open', function () {
ws2.packet({
type: 'connect'
, endpoint: 'a'
});
});
});
}
++connect;
if (++calls === expected) finish();
}
Expand All @@ -197,17 +202,12 @@ module.exports = {
if (++calls === expected) finish();
}
});

cl.handshake(function (sid) {
ws2 = websocket(cl, sid);

ws2.on('open', function () {
ws2.packet({
type: 'connect'
, endpoint: 'a'
});
ws1.on('open', function() {
ws1.packet({
type: 'connect'
, endpoint: 'a'
});
})
});
})
},

Expand Down

0 comments on commit 57b0ce7

Please sign in to comment.