Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('express server with requestLogger and scrubFields does not lock up under load', (done) => {
loadtest.loadTest(loadOptions, (error, results) => {
if (error) {
done(error);
return;
}
printResults(results);
expect(results.totalErrors).to.eql(0, 'there are no request errors');
expect(results.meanLatencyMs).to.be.lte(10, 'mean response is less than 10ms');
expect(results.percentiles['99']).to.be.lte(20, '99% of responses under 20ms');
// expect(results.maxLatencyMs).to.be.lte(40, 'max response is less than 40ms');
done();
});
});
});
];
const options = {
statusCallback,
// requestGenerator,
method: 'post',
concurrency: 6,
body: {
urls
},
url: 'http://localhost:3000/api/books',
contentType: 'application/json',
maxRequests: 300
};
loadtest.loadTest(options, (error, result) => {
if (error) {
return console.error('Got an error: %s', error);
}
console.log('Tests run successfully');
console.log(result);
return undefined;
});
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
const loadtest = require('loadtest');
if(process.argv.length <= 2) {
console.log("Options needed, got " + JSON.stringify(process.argv))
process.exit(1);
}
try {
let options = JSON.parse(process.argv[2])
// do some validation?
loadtest.loadTest(options, function(error, result) {
if (error) {
console.error('Load test return an error: %s', error);
process.exit(1);
}
console.log(result);
});
} catch (err) {
console.error(err);
process.exit(1);
}
test('Homepage should handle 50 requests in under a second', function(done){
var options = {
url: 'http://localhost:3000',
concurrency: 4,
maxRequests: 50,
};
loadtest.loadTest(options, function(err,result){
expect(!err);
expect(result.totalTimeSeconds < 1);
done();
});
});
const report = await new Promise((res, rej) => {
loadTest(options, (err, result) => {
if (err) {
rej(err);
} else {
res(result);
}
});
});
logger.debug('Perf report', { report });