alexfernandez / loadtest

Runs a load test on the selected URL. Fast and easy to use. Can be integrated in your own workflow using the API.
MIT License
2.57k stars 209 forks source link

indexParam value is not dynamically replaced in body after concurrency's number of requests #198

Closed ashishnetworks closed 1 year ago

ashishnetworks commented 3 years ago

I was doing one of the performance tests for my current project and I realized that indexParam is not dynamically replaced in the body after the initial concurrency number of requests. Look at the following code of loadTestScript.js

var loadtest = require('loadtest')

function statusCallback (error, result, latency) {
  console.log('Request index: %j, totalError %j, errorcode frequency %j error %j and RPS %j', result ? result.requestIndex : 'NOT FOUND', latency.totalErrors, latency.errorCodes, error, latency.rps)
}

let counter = 0
function optionsObject() {
    return {
        url: 'http://localhost:3000?name=value',
        maxRequests: 10 ,
        concurrency: 3,
        method: 'POST',
        contentType: 'application/json',
        headers: {
            'Content-Type': 'application/json'
        },
        indexParam: "value",
        body:   {
            id: "value"
        },
    statusCallback: statusCallback,
    indexParamCallback: function () {
        return ++counter
    }}
}

loadtest.loadTest(optionsObject(), function (error, result) {
    // This blocks gets called when whole test is finished
  if (error) {
    console.log('Got an error: %s', error)
  }
  console.log('Got the following result from the test>>\n', result)
})

To check if values are dynamically received in the server, I ran a local express server on localhost:3000 with the following code

let reqCount = 0
app.post('/', function (req, res) {
    console.log('------------------------------------')
    console.log(`Received req for count ${++reqCount}`)
    console.log(`Query params: `, req.query)
    console.log(`Req body: `, req.body)
    res.send('hello world')
})

and then I ran the loadTestScript.js script with the node loadTestScript.js command and the following is the output that I got

image

If you look at the request numbers 1, 2 and 3 everything looks good. But from request count 4 you will notice the value received in the body is static (last value of the request) while the name's value received through the query parameter is still dynamic. FYI if I increase the concurrency to 5 then the body will be dynamic till the 5th requests but later that it will stick to a static value. I believe the purpose of indexParam in the body is to provide dynamic values in the body irrespective of a number of concurrencies, currently, it's not serving that purpose.

cc: @alexfernandez

alexfernandez commented 3 years ago

Excellent bug report! :+1: Care to debug it and send a pull request? :wink:

alexfernandez commented 1 year ago

Sorry for the long delay. Should work now, please review.