Skip to content

Instantly share code, notes, and snippets.

@nathanhammond
Created October 26, 2010 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanhammond/647739 to your computer and use it in GitHub Desktop.
Save nathanhammond/647739 to your computer and use it in GitHub Desktop.
Test case for interesting connection limit bug.
/*
To run test...
1. Get wsbench. Update the shebang in wsbench/wsbench if necessary.
> git clone git://github.com/pgriess/wsbench.git
> cd wsbench
2. Add in our test case by saving this file (wsbenchtest.js) into the wsbench directory.
3. Start the socket.io chat example.
4. Spin up a bunch of connections using wsbench
> ./wsbench -c 245 -r 25 -S ./wsbenchtest.js ws://localhost:8080/socket.io/websocket
5. Open the chat example in your browser: http://localhost:8080/chat.html
6. Type in a test message, ensure that the log in the wsbench view notes that all received. At this point there are 246 active connections.
7. Open the 247th in a new tab, follow the same procedure as in 6. Works.
8. Open the 248th in a new tab. Fails with "404" message.
NOTES:
I may be doing this completely wrong.
Your "death" number may be different.
ENV:
OS X 10.6.4
socket.io master/HEAD
node v0.2/HEAD
wsbench master/HEAD
*/
var cnt = 0;
var clients = 0;
ioutils = require('../lib/socket.io/utils.js');
module.exports = function(ws) {
ws.onopen = function() {
clients++;
console.log("Clients: " + clients);
if(clients % 100 == 0) {
console.log("Clients: " + clients);
}
};
ws.onmessage = function(m) {
var curMsg = ioutils.decode(m.data).pop();
//return the heartbeat
if(curMsg.substring(0,3) == '~h~') {
var msg = '~h~' + curMsg.substr(3);
ws.send(ioutils.encode(msg));
return;
}
if(curMsg.indexOf("~j~") === 0) {
curMsg = curMsg.substring(3);
} else {
return;
}
var c = ++cnt/clients;
if(c == 1) {
console.log("All " + clients + " received: " + curMsg);
cnt = 0;
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment