Socket
Socket
Sign inDemoInstall

loadtest

Package Overview
Dependencies
26
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.1.0 to 4.2.0

1

index.d.ts

@@ -23,2 +23,3 @@ declare namespace loadtest {

statusCallback?(error: Error, result: any, latency: LoadTestResult): void;
contentInspector?(result: any): void;
}

@@ -25,0 +26,0 @@

17

lib/httpClient.js

@@ -174,5 +174,5 @@ 'use strict';

if (typeof this.params.requestGenerator == 'function') {
request = this.params.requestGenerator(this.params, this.options, lib.request, this.getConnect(id, requestFinished));
request = this.params.requestGenerator(this.params, this.options, lib.request, this.getConnect(id, requestFinished, this.params.contentInspector));
} else {
request = lib.request(this.options, this.getConnect(id, requestFinished));
request = lib.request(this.options, this.getConnect(id, requestFinished, this.params.contentInspector));
}

@@ -207,2 +207,5 @@ if (this.params.hasOwnProperty('timeout')) {

errorCode = result.statusCode;
if (result.customErrorCode !== undefined) {
errorCode = errorCode + ":" + result.customErrorCode
}
} else {

@@ -237,3 +240,3 @@ errorCode = '-1';

*/
getConnect(id, callback) {
getConnect(id, callback, contentInspector) {
let body = '';

@@ -259,5 +262,11 @@ return connection => {

};
if (contentInspector) {
contentInspector(result)
}
if (connection.statusCode >= 400) {
return callback('Status code ' + connection.statusCode, result);
}
if (result.customError) {
return callback('Custom error: ' + result.customError, result);
}
callback(null, result);

@@ -284,3 +293,3 @@ });

*/
exports.test = function(callback) {
exports.test = function (callback) {
testing.run([

@@ -287,0 +296,0 @@ testHttpClient,

@@ -179,2 +179,3 @@ 'use strict';

this.running = false;
this.latency.running = false;

@@ -181,0 +182,0 @@ Object.keys(this.clients).forEach(index => {

@@ -294,3 +294,3 @@ 'use strict';

Object.keys(results.errorCodes).forEach(errorCode => {
const padding = ' '.repeat(4 - errorCode.length);
const padding = ' '.repeat(errorCode.length < 4 ? 4 - errorCode.length : 1);
log.info(' %s%s: %s errors', padding, errorCode, results.errorCodes[errorCode]);

@@ -297,0 +297,0 @@ });

{
"name": "loadtest",
"version": "4.1.0",
"version": "4.2.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.",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/alexfernandez/loadtest",

@@ -679,2 +679,27 @@ [![Build Status](https://secure.travis-ci.org/alexfernandez/loadtest.svg)](http://travis-ci.org/alexfernandez/loadtest)

#### `contentInspector`
A function that would be executed after every request before its status be added to the final statistics.
The is can be used when you want to mark some result with 200 http status code to be failed or error.
The `result` object passed to this callback function has the same fields as the `result` object passed to `statusCallback`.
`customError` can be added to mark this result as failed or error. `customErrorCode` will be provided in the final statistics, in addtion to the http status code.
Example:
```javascript
fucntion contentInspector (result) => {
if (result.statusCode == 200) {
const body = JSON.parse(result.body)
// how to examine the body depends on the content that the service returns
if (body.status.err_code !== 0) {
result.customError = body.status.err_code + " " + body.status.msg
result.customErrorCode = body.status.err_code
}
}
},
```
### Results

@@ -681,0 +706,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc