Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i load test a post API using 'loadtest' nodejs module?

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?

like image 245
Atif Hussain Avatar asked May 21 '15 05:05

Atif Hussain


People also ask

How can we do load testing of an API?

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.

How do you load test a postman?

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.


1 Answers

there is a typo at the declaration of the Content-Type. (The second i is missing.)

Use

contentType: 'application/json',

instead, then it works.

like image 121
Jens Avatar answered Nov 14 '22 23:11

Jens