//////////////////////////////////////////////////// // // Usage : node run_tests.js [nb user keys] [nb packets to send per user] [nb Requests Before Wait] [wait time in seconds] // // Example : node run_tests.js 5 50 20 10 // It will generate 5 userKeys and will send 50 packet for each userKey. The process will wait 10 secons every 20 requests // // var dgram = require('dgram'), util = require('util'); var DEBUG = false; // Splice arguments var arguments = process.argv.splice(2); var nbUserKeys = parseInt(arguments[0]); var nbPacketsPerUser = parseInt(arguments[1]); var nbRequestsBeforeWait = parseInt(arguments[2]); var waitTime = parseInt(arguments[3]); if(!nbRequestsBeforeWait) nbRequestsBeforeWait = 10; // Default nbRequests before wait: 10; if(!waitTime) waitTime = 5; //Default wait time: 5 seconds var randomUserKeys = []; var keysPattern = "secretKey.${userKey}.monsite.home.clicks:${value}|${type}"; // // ### function randomString (bits) // #### @bits {integer} The number of bits for the random base64 string returned to contain // randomString returns a pseude-random ASCII string which contains at least the specified number of bits of entropy // the return value is a string of length ⌈bits/6⌉ of characters from the base64 alphabet // var randomString = function (bits) { var chars, rand, i, ret; chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-'; ret = ''; // in v8, Math.random() yields 32 pseudo-random bits (in spidermonkey it gives 53) while (bits > 0) { // 32-bit integer rand = Math.floor(Math.random() * 0x100000000); // base 64 means 6 bits per character, so we use the top 30 bits from rand to give 30/6=5 characters. for (i = 26; i > 0 && bits > 0; i -= 6, bits -= 6) { ret += chars[0x3F & rand >>> i]; } } return ret; }; /** * Generate a number between 1 and maxValue included */ var randomInt = function (maxValue) { return(Math.floor(Math.random() * maxValue) + 1); } ///////////////////////////////////////////////////////////////////////////// // Generate userKeys for(var i=0; i -1) { if(availableUserNames.length == 1) { availableUserNames = []; process.stdout.write("\n"); console.log("End loop."); console.log("-> Status map :\n" + util.inspect(statusMap)); } else { availableUserNames.splice(userKeyPos, 1); } } } index ++; if(DEBUG) console.log(util.inspect(statusMap)); if(DEBUG) console.log(""); if(availableUserNames.length > 0 && index % nbRequestsBeforeWait == 0) { console.log(" | " + nbRequestsBeforeWait + " packets sent."); process.stdout.write("\n"); console.log("- waiting " + waitTime + " seconds -\n"); setTimeout(function(){ sendPackets(); }, waitTime*1000); } else if(availableUserNames.length > 0) { sendPackets(); } if(index == nbUserKeys*nbPacketsPerUser) { process.exit(0); } } if(availableUserNames.length > 0) { sendPackets(); for(var i=0; i<5000000; ++i){} }