Socket
Socket
Sign inDemoInstall

loadtest

Package Overview
Dependencies
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loadtest - npm Package Compare versions

Comparing version 4.2.0 to 5.0.0

lib/config.js

73

bin/loadtest.js

@@ -17,2 +17,3 @@ #!/usr/bin/env node

const packageJson = require(__dirname + '/../package.json');
const config = require('../lib/config');

@@ -62,5 +63,8 @@ // init

}
const configuration = config.loadConfig(options);
options.url = options.args[0];
options.agentKeepAlive = options.keepalive || options.agent;
options.indexParam = options.index;
options.agentKeepAlive = options.keepalive || options.agent || configuration.agentKeepAlive;
options.indexParam = options.index || configuration.indexParam;

@@ -99,17 +103,31 @@ //TODO: add index Param

}
if(options.rps) {
options.requestsPerSecond = parseFloat(options.rps);
if(!options.method) {
options.method = configuration.method;
}
if(!options.body) {
if(configuration.body) {
options.body = configuration.body;
} else if(configuration.file) {
options.body = readBody(configuration.file, 'configuration.request.file');
}
}
options.requestsPerSecond = options.rps ? parseFloat(options.rps) : configuration.requestsPerSecond;
if(!options.key) {
options.key = configuration.key;
}
if(options.key) {
options.key = fs.readFileSync(options.key);
}
if(!options.cert) {
options.cert = configuration.cert;
}
if(options.cert) {
options.cert = fs.readFileSync(options.cert);
}
const defaultHeaders = {
host: urlLib.parse(options.url).host,
'user-agent': 'loadtest/' + packageJson.version,
accept: '*/*'
};
const defaultHeaders = options.headers ? {} : configuration.headers;
defaultHeaders['host'] = urlLib.parse(options.url).host;
defaultHeaders['user-agent'] = 'loadtest/' + packageJson.version;
defaultHeaders['accept'] = '*/*';
if (options.headers) {

@@ -119,3 +137,7 @@ headers.addHeaders(options.headers, defaultHeaders);

}
options.headers = defaultHeaders;
if (!options.requestGenerator) {
options.requestGenerator = configuration.requestGenerator;
}
if (options.requestGenerator) {

@@ -125,3 +147,34 @@ options.requestGenerator = require(path.resolve(options.requestGenerator));

options.headers = defaultHeaders;
// Use configuration file for other values
if(!options.maxRequests) {
options.maxRequests = configuration.maxRequests;
}
if(!options.concurrency) {
options.concurrency = configuration.concurrency;
}
if(!options.maxSeconds) {
options.maxSeconds = configuration.maxSeconds;
}
if(!options.timeout && configuration.timeout) {
options.timeout = configuration.timeout;
}
if(!options.contentType) {
options.contentType = configuration.contentType;
}
if(!options.cookies) {
options.cookies = configuration.cookies;
}
if(!options.secureProtocol) {
options.secureProtocol = configuration.secureProtocol;
}
if(!options.insecure) {
options.insecure = configuration.insecure;
}
if(!options.recover) {
options.recover = configuration.recover;
}
if(!options.proxy) {
options.proxy = configuration.proxy;
}
loadTest.loadTest(options);

@@ -128,0 +181,0 @@

@@ -12,2 +12,3 @@ #!/usr/bin/env node

const testServer = require('../lib/testserver');
const config = require('../lib/config')

@@ -20,2 +21,3 @@ // init

});
const configuration = config.loadConfig(options)
if (options.args && options.args.length == 1) {

@@ -38,3 +40,13 @@ options.port = parseInt(options.args[0], 10);

if(!options.delay) {
options.delay = configuration.delay
}
if(!options.error) {
options.error = configuration.error
}
if(!options.percent) {
options.percent = configuration.percent
}
testServer.startServer(options);

@@ -14,2 +14,4 @@ 'use strict';

const Log = require('log');
const { execFile } = require('child_process');
const { join } = require('path');

@@ -55,3 +57,29 @@ // globals

/**
* Run an integration test using configuration file.
*/
function testIntegrationFile(callback) {
const server = testserver.startServer({ port: PORT }, error => {
if (error) {
return callback(error);
}
execFile('node',
[join(__dirname, '..', 'bin', 'loadtest.js'), 'http://localhost:' + PORT],
{ cwd: join(__dirname, '..', 'test') },
(error, stdout) => {
if (error) {
return callback(error);
}
server.close(error => {
if (error) {
return callback(error);
}
return callback(null, 'Test results: ' + stdout);
});
});
});
}
/**

@@ -131,3 +159,3 @@ * Run an integration test.

log.debug('Running all tests');
testing.run([testIntegration, testDelay, testWSIntegration], 4000, callback);
testing.run([testIntegration, testIntegrationFile, testDelay, testWSIntegration], 4000, callback);
};

@@ -134,0 +162,0 @@

5

package.json
{
"name": "loadtest",
"version": "4.2.0",
"version": "5.0.0",
"description": "Run load tests for your web application. Mostly ab-compatible interface, with an option to force requests per second. Includes an API for automated load testing.",

@@ -18,2 +18,3 @@ "homepage": "https://github.com/alexfernandez/loadtest",

"agentkeepalive": "^2.0.3",
"confinode": "^2.1.1",
"https-proxy-agent": "^2.2.1",

@@ -38,3 +39,3 @@ "log": "1.4.*",

"engines": {
"node": ">=8"
"node": ">=10"
},

@@ -41,0 +42,0 @@ "bin": {

@@ -36,5 +36,6 @@ [![Build Status](https://secure.travis-ci.org/alexfernandez/loadtest.svg)](http://travis-ci.org/alexfernandez/loadtest)

Versions 4 and later should be used at least with Node.js v8 or later:
Versions 5 and later should be used at least with Node.js v10 or later:
* Node.js v8 or later: ^4.0.0.
* Node.js v10 or later: ^5.0.0
* Node.js v8 or later: 4.x.y.
* Node.js v6 or earlier: ^3.1.0.

@@ -777,2 +778,42 @@

### Configuration file
It is possible to put configuration options in a file named `.loadtestrc` in your working directory or in a file whose name is specified in the `loadtest` entry of your `package.json`. The options in the file will be used only if they are not specified in the command line.
The expected structure of the file is the following:
```json
{
"delay": "Delay the response for the given milliseconds",
"error": "Return an HTTP error code",
"percent": "Return an error (default 500) only for some % of requests",
"maxRequests": "Number of requests to perform",
"concurrency": "Number of requests to make",
"maxSeconds": "Max time in seconds to wait for responses",
"timeout": "Timeout for each request in milliseconds",
"method": "method to url",
"contentType": "MIME type for the body",
"body": "Data to send",
"file": "Send the contents of the file",
"cookies": {
"key": "value"
},
"headers": {
"key": "value"
},
"secureProtocol": "TLS/SSL secure protocol method to use",
"insecure": "Allow self-signed certificates over https",
"cert": "The client certificate to use",
"key": "The client key to use",
"requestGenerator": "JS module with a custom request generator function",
"recover": "Do not exit on socket receive errors (default)",
"agentKeepAlive": "Use a keep-alive http agent",
"proxy": "Use a proxy for requests",
"requestsPerSecond": "Specify the requests per second for each client",
"indexParam": "Replace the value of given arg with an index in the URL"
}
```
For more information about the actual configuration file name, read the [confinode user manual](https://github.com/slune-org/confinode/blob/master/doc/en/usermanual.md#configuration-search). In the list of the [supported file types](https://github.com/slune-org/confinode/blob/master/doc/extensions.md), please note that only synchronous loaders can be used with _loadtest_.
### Complete Example

@@ -779,0 +820,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc