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 0.1.11 to 0.1.12

141

lib/loadtest.js

@@ -44,13 +44,53 @@ 'use strict';

var requestTimer;
var id;
var options;
var message;
// init
if (params.agentKeepAlive)
init();
/**
* Init options and message to send.
*/
function init()
{
var keepalive = require('agentkeepalive');
var keepAliveAgent = new keepalive({
maxSockets: params.concurrency,
maxKeepAliveRequests: 0, // max requests per keepalive socket, default is 0, no limit
maxKeepAliveTime: 3000 // keepalive for 30 seconds
});
if (params.agentKeepAlive)
{
var keepalive = require('agentkeepalive');
var keepAliveAgent = new keepalive({
maxSockets: params.concurrency,
maxKeepAliveRequests: 0, // max requests per keepalive socket, default is 0, no limit
maxKeepAliveTime: 3000 // keepalive for 30 seconds
});
}
options = urlLib.parse(params.url);
if (params.noAgent)
{
options.agent = false;
}
if (params.agentKeepAlive)
{
options.agent = keepAliveAgent;
}
if (params.method)
{
options.method = params.method;
}
if (params.payload)
{
if (typeof params.payload == 'string')
{
message = params.payload;
}
else if (typeof params.payload == 'object')
{
message = JSON.stringify(params.payload);
}
else
{
log.error('Unrecognized payload: %s', typeof params.payload);
}
options.headers = {
'Content-Length': message.length,
};
}
}

@@ -91,35 +131,4 @@

}
id = operation.latency.start(id);
var options = urlLib.parse(params.url);
if (params.noAgent)
{
options.agent = false;
}
if (params.agentKeepAlive)
{
options.agent = keepAliveAgent;
}
if (params.method)
{
options.method = params.method;
}
var message;
if (params.payload)
{
if (typeof params.payload == 'string')
{
message = params.payload;
}
else if (typeof params.payload == 'object')
{
message = JSON.stringify(params.payload);
}
else
{
log.error('Unrecognized payload: %s', typeof params.payload);
}
options.headers = {
'Content-Length': message.length,
};
}
var id = operation.latency.start(id);
var requestFinished = getRequestFinisher(id);
var request = http.request(options, getConnect(id, requestFinished));

@@ -132,3 +141,3 @@ if (message)

{
log.error('Error: %s', error.message);
requestFinished('Connection error: ' + error.message);
});

@@ -139,21 +148,24 @@ request.end();

/**
* One request has finished, go for the next.
* Get a function that finishes one request and goes for the next.
*/
function requestFinished(error, result)
function getRequestFinisher(id)
{
if (error)
return function(error, result)
{
log.debug('Connection %s failed: %s', id, error);
}
else
{
log.debug('Connection %s ended', id);
}
operation.latency.end(id);
var callback;
if (!params.requestsPerSecond)
{
callback = self.makeRequest;
}
operation.callback(error, result, callback);
if (error)
{
log.debug('Connection %s failed: %s', id, error);
}
else
{
log.debug('Connection %s ended', id);
}
operation.latency.end(id);
var callback;
if (!params.requestsPerSecond)
{
callback = self.makeRequest;
}
operation.callback(error, result, callback);
};
}

@@ -200,2 +212,3 @@

* - agentKeepAlive: if true, then use a special agent with keep-alive.
* - debug: show debug messages.
* - quiet: do not log any messages.

@@ -226,2 +239,6 @@ * An optional callback will be called if/when the test finishes.

options.concurrency = options.concurrency || 1;
if (options.debug)
{
log.level = Log.DEBUG;
}
if (callback)

@@ -372,2 +389,4 @@ {

console.log(' --index param Replace the value of param with an index in the URL');
console.log(' --quiet Do not log any messages');
console.log(' --debug Show debug messages');
}

@@ -416,2 +435,8 @@

return true;
case '--quiet':
options.quiet = true;
return true;
case '--debug':
options.debug = true;
return true;
}

@@ -418,0 +443,0 @@ console.error('Unknown option %s', argument);

@@ -49,4 +49,8 @@ 'use strict';

{
log.level = 'notice';
log.level = Log.NOTICE;
}
if (options.debug)
{
log.level = Log.DEBUG;
}

@@ -53,0 +57,0 @@ /**

{
"name": "loadtest",
"version": "0.1.11",
"version": "0.1.12",
"description": "Load test scripts.",

@@ -5,0 +5,0 @@ "homepage": "http://milliearth.org/",

Sorry, the diff of this file is not supported yet

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