-
-
Save shrikanthkr/22b6b817fd2edb1b0e46 to your computer and use it in GitHub Desktop.
Socke IO testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.info("Socket.io chat test client"); | |
io = require('socket.io-client'); | |
var args = process.argv.slice(2); | |
Test = {}; | |
Test.connections = parseInt(args[0]) || 100; | |
Test.completedProcesses = 0; | |
Test.failures = 0; | |
Test.pingServer = function(socket_n) { | |
var j = socket_n; | |
socket = io.connect('http://localhost:5001', {'force new connection': true}); | |
//socket = io.connect('http://aw.7zero.com:5001', {'force new connection': true}); | |
socket.my_nick = process.pid.toString() + "_" + j.toString(); | |
console.log('Conec:'+socket.my_nick ); | |
Test.connection(socket,socket_n); | |
}; | |
Test.connection = function(socket,socket_n) { | |
var inner_socket = socket; | |
inner_socket.on('connect', function () { | |
console.info("Connected[" + socket_n + "] => " + inner_socket.my_nick); | |
Test.monitorForCompletion(); | |
inner_socket.emit('nickname', inner_socket.my_nick, function (set) { }); | |
//var interval = 3; | |
var interval = Math.floor(Math.random()*10001) + 5000; | |
setInterval(function() { | |
inner_socket.emit('message', "Regular timer message every " + interval + " ms"); | |
}, interval); | |
}); | |
socket.on('error', function (err_msg) { | |
console.error("Connection Error:" + err_msg); | |
Test.updateFailureCount(); | |
Test.monitorForCompletion(); | |
}); | |
socket.on('disconnect', function () { | |
console.info("Disconnected"); | |
Test.updateFailureCount(); | |
Test.monitorForCompletion(); | |
}); | |
}; | |
Test.monitorForCompletion = function() { | |
Test.completedProcesses++; | |
console.log('*********'+Test.connections+':'+Test.completedProcesses+'**********'); | |
if(Test.completedProcesses == Test.connections){ | |
Test.showStatus(); | |
process.kill(); | |
} | |
} | |
Test.updateFailureCount = function() { | |
Test.failures++; | |
console.log('*********'+Test.failures+'**********'); | |
}; | |
Test.showStatus = function() { | |
var success = Test.connections - Test.failures, | |
failures = Test.failures; | |
console.log('Success Hits: '+ success ); | |
console.log('Failures: '+failures); | |
console.log('Success Percent: '+(success*100/Test.connections )); | |
console.log('Failure Percent: '+(failures*100/Test.connections )); | |
} | |
console.log('Total connections:'+Test.connections); | |
for (var socket_n = 0; socket_n < Test.connections; socket_n++) { | |
Test.pingServer(socket_n); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment