I need to run a CasperJS script many times at different moments to simulate simultaneous connections on my website. The script is connecting to my website and do some others actions and I want to see if the server can handle it. I know it is possible to do that using NodeJS (CasperJS, parallel browsing WITH the testing framework check the response) and his child_process module, but I couldn't succeed to do it from now. I want to launch a couple of process every 5 secs until I have X process launch at the same time. I would like an example of doing this using this pseudo code logic.
var deth = 8;
var factor = 2;
var spawn = require('child_process').spawn;
function launchXProcess(nb_process)
{
for (var i = 1; i <= nb_process; i++) {
// spawn a new process 'casperjs scritp.js'
// log the process outputs
// keep going
}
}
function newPoolOfProcess(i)
{
// First time
if (i === 1) {
launchXProcess(i);
i++;
// wait 5 sec and launch the next one
setTimeout(newPoolOfProcess(i), 5000);
}
// Reach the last pool, launch it and exit
if (i === deth) {
launchXProcess(i);
process.exit(code = 0);
} else {
launchXProcess(i);
i *= factor
// wait 5 sec and launch the next one
setTimeout(newPoolOfProcess(i), 5000);
}
}
// start
newPoolOfProcess(1);
Following this logic at a T moment I will have many process connected to my website. The CasperJS script is taking more than a minute to be completed to make sure I will have many process connected before its done. I have tried to use the spawn method from the chil_process but without success. Please show me how to complete that, thanks