I am using the loadtest nodejs module to test stress testing on APIs in nodejs script. The Get call syntax is working however post call not. the code is below.
function optionsObject() {
return {
url: 'http://localhost:3000/api/v2/signup',
maxRequests: 1,
concurrency: 1,
method: 'POST',
contentType: 'applicaton/json',
body: {
password: 'test',
email: '[email protected]',
name: 'kPYgJ6Rg5wnExt8hTXQIHDn2LaCMsytjhQzp'
}
}
}
loadtest.loadTest(optionsObject(), function (error, result) {
if (error) {
console.log('Got an error: %s', error);
} else {
console.log(result);
}
});
Results:
{
totalRequests: 1,
totalErrors: 1,
totalTimeSeconds: 0.025545716,
rps: 39,
meanLatencyMs: 20,
maxLatencyMs: 20,
percentiles: { '50': 20, '90': 20, '95': 20, '99': 20 },
errorCodes: { '400': 1 }
}
can anyone help that why i am getting bad request error 400?
Use Production Data: A common technique for load testing is to clone anonymized production database data into a test environment where load tests can run. That way, you're using the most realistic data possible in your tests.
For the load test to work, you need to run all the tests at once to create a significant load. Postman's Collection Runner can be used to load test an API by specifying a large number of iterations and running a number of such collections in parallel to create a high throughput.
there is a typo at the declaration of the Content-Type. (The second i is missing.)
Use
contentType: 'application/json',
instead, then it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With