body set to null in the statusCallback with requestGenerator
Closed this issue · 2 comments
StfCG2 commented
Hi Alex,
I am using the requestGenerator function and the request itself is working fine.
However, the statusCallback displays a "body":"null" value rather than displaying the actual content of my request.
I am not sure whether that is a bug or if there is a way to address that simply?
Thanks,
const loadtest = require('loadtest');
const uuidv4 = require('uuid/v4');
const fs = require('fs');
function statusCallback(error, result, latency) {
let line1 = `Current latency: ${JSON.stringify(latency)}`;
let line2 = `Result: ${JSON.stringify(result)}`;
let line3 = `Error: ${error}`;
let output = '';
output = output + ' \n ' + line1 + ' \n ' + ' \n ' + line2 + ' \n ' + line3 + '\n ------------------------------------------- \n';
fs.appendFile('log.txt', output, (err) => {
if (err) throw err;
// console.log('The "data to append" was appended to file!');
});
};
var options = {
url: 'xxxxxxxxx,
headers:{
'Content-Type': 'application/json'
},
requestsPerSecond: 5,
concurrency: 1,
maxSeconds: 10,
agentKeepAlive: 'Connection: Keep-alive',
method: 'POST',
requestGenerator: function (params, options, client, callback) {
var body = {
'uuid': uuidv4(),
'account': 'xxxxxxx',
'profile': 'xxxxxxx',
'type': 'xxxxxxx'
};
var message = JSON.stringify(body);
var request = client(options, callback);
request.write(message);
return request;
},
statusCallback: statusCallback
};
loadtest.loadTest(options, function (error) {
if (error) {
return console.error('Got an error: %s', error);
}
console.log('Tests run successfully');
});
And here is the log output:
Current latency: {"totalRequests":5,"totalErrors":0,"totalTimeSeconds":1.1973539960000001,"rps":4,"meanLatencyMs":72.6,"maxLatencyMs":183,"minLatencyMs":39,"percentiles":{"50":39,"90":183,"95":183,"99":183},"errorCodes":{}}
Result: {"host":"removed","path":"/Dev/log","method":"POST","statusCode":200,"body":"null","headers":{"content-type":"application/json","content-length":"4","connection":"keep-alive","date":"Fri, 03 Nov 2017 14:06:52 GMT"},"requestElapsed":39.021358,"requestIndex":4,"instanceIndex":0}
Error: null
-------------------------------------------
alexfernandez commented
Hi @StfCG2, sorry for the delay. Looks like a bug, care to look into it? Thanks!
alexfernandez commented
Closing due to inactivity, please reopen if needed.