Skip to content

Instantly share code, notes, and snippets.

@Hiestaa
Created September 20, 2019 19:46
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 Hiestaa/dd3e68b66d4f875dfcfd784c82ba284d to your computer and use it in GitHub Desktop.
Save Hiestaa/dd3e68b66d4f875dfcfd784c82ba284d to your computer and use it in GitHub Desktop.
Overload a webserver with a large number of queries for testing purposes (don't be a dick...)
var argv = require('yargs')
.usage('Usage: $0 -n num -q url[?queryString] [-m method] [-b body]')
.demandOption(['n', 'q'])
.argv;
var axios = require('axios');
promises = []
Promise.all([...Array(parseInt(argv.n, 10))].map((data, index) => {
let p
if (argv.b) {
p = axios[argv.m || 'post'](argv.q, argv.b);
}
else {
p = axios[argv.m || 'get'](argv.q);
}
// with a body,
return p.then(response => {
console.log("Response for request #" + index + ':');
console.log(response.status + ' ' + response.statusText + ': ' + JSON.stringify(response.data));
return response;
})
.catch((error) => {
console.error("Error while submitting request #" + index);
console.error(error);
});
})).then(() => {
console.log("Successfully received " + argv.n + ' responses.')
}).catch(error => {
console.error(error);
});
{
"name": "overload",
"version": "1.0.0",
"description": "Overload a webserver with a large number of queries for testing purposes (don't be a dick...)",
"main": "overload.js",
"dependencies": {
"axios": "^0.19.0",
"yargs": "^14.0.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"http",
"overload",
"testing"
],
"author": "Romain GUYOT de la HARDROUYERE",
"license": "MIT"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment