Skip to content

Commit

Permalink
Added memory leaks tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
rauchg committed Jul 31, 2011
1 parent 195eba7 commit a79b2fa
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/leaks/socket.leaktest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*!
* socket.io-node
* Copyright(c) 2011 LearnBoost <[email protected]>
* MIT Licensed
*/

/**
* Test dependencies.
*/

require.paths.unshift(__dirname + '/../../lib');

var assertvanish = require('assertvanish')
, common = require('../common')
, ports = 15800;

function resultCallback (leaks, leakedSocket) {
if (leaks) {
console.error('Leak detected');
process.exit(1);
} else {
console.error('No leaks');
process.exit(0);
}
};

/**
* Test.
*/

var cl = client(++ports);
var io = create(cl);

io.sockets.on('connection', function (socket) {
console.log('connected');

socket.on('disconnect', function() {
console.log("client gone");
setTimeout(gc, 1000);
assertvanish(socket, 2000, {silent: true, callback: resultCallback});
});
});

setTimeout(function() {
cl.handshake(function (sid) {
var ws = websocket(cl, sid);
ws.on('open', function () {
console.log('open!');
setTimeout(function() {
ws.close();
}, 500);
});
});
}, 100);

0 comments on commit a79b2fa

Please sign in to comment.