Comparing version 5.0.4 to 5.1.0
@@ -24,2 +24,3 @@ declare namespace loadtest { | ||
contentInspector?(result: any): void; | ||
indexParamCallback?(): string; | ||
} | ||
@@ -26,0 +27,0 @@ |
@@ -91,4 +91,4 @@ 'use strict'; | ||
constructor(options, callback) { | ||
this.options = options | ||
this.finalCallback = callback | ||
this.options = options; | ||
this.finalCallback = callback; | ||
this.running = true; | ||
@@ -114,3 +114,3 @@ this.latency = null; | ||
this.showTimer = new HighResolutionTimer(SHOW_INTERVAL_MS, () => this.latency.showPartial()); | ||
this.showTimer.unref() | ||
this.showTimer.unref(); | ||
} | ||
@@ -144,11 +144,21 @@ | ||
const url = this.options.url; | ||
const strBody = JSON.stringify(this.options.body); | ||
for (let index = 0; index < this.options.concurrency; index++) { | ||
if (this.options.indexParam) { | ||
this.options.url = url.replace(new RegExp(this.options.indexParam, 'g'), index); | ||
if(this.options.body) { | ||
let strBody = JSON.stringify(this.options.body); | ||
strBody = strBody.replace(new RegExp(this.options.indexParam, 'g'), index); | ||
this.options.body = JSON.parse(strBody); | ||
let oldToken = new RegExp(this.options.indexParam, 'g'); | ||
if(this.options.indexParamCallback instanceof Function) { | ||
let customIndex = this.options.indexParamCallback(); | ||
this.options.url = url.replace(oldToken, customIndex); | ||
if(this.options.body) { | ||
let body = strBody.replace(oldToken, customIndex); | ||
this.options.body = JSON.parse(body); | ||
} | ||
} | ||
else { | ||
this.options.url = url.replace(oldToken, index); | ||
if(this.options.body) { | ||
let body = strBody.replace(oldToken, index); | ||
this.options.body = JSON.parse(body); | ||
} | ||
} | ||
} | ||
@@ -225,3 +235,57 @@ let constructor = httpClient.create; | ||
function testIndexParam(callback) { | ||
const options = { | ||
url: 'http://localhost:7357/replace', | ||
concurrency:1, | ||
quiet: true, | ||
maxSeconds: 0.1, | ||
indexParam: "replace" | ||
}; | ||
exports.loadTest(options, callback); | ||
} | ||
function testIndexParamWithBody(callback) { | ||
const options = { | ||
url: 'http://localhost:7357/replace', | ||
concurrency:1, | ||
quiet: true, | ||
maxSeconds: 0.1, | ||
indexParam: "replace", | ||
body: '{"id": "replace"}' | ||
}; | ||
exports.loadTest(options, callback); | ||
} | ||
function testIndexParamWithCallback(callback) { | ||
const options = { | ||
url: 'http://localhost:7357/replace', | ||
concurrency:1, | ||
quiet: true, | ||
maxSeconds: 0.1, | ||
indexParam: "replace", | ||
indexParamCallback: function() { | ||
//https://gist.github.com/6174/6062387 | ||
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); | ||
} | ||
}; | ||
exports.loadTest(options, callback); | ||
} | ||
function testIndexParamWithCallbackAndBody(callback) { | ||
const options = { | ||
url: 'http://localhost:7357/replace', | ||
concurrency:1, | ||
quiet: true, | ||
maxSeconds: 0.1, | ||
body: '{"id": "replace"}', | ||
indexParam: "replace", | ||
indexParamCallback: function() { | ||
//https://gist.github.com/6174/6062387 | ||
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); | ||
} | ||
}; | ||
exports.loadTest(options, callback); | ||
} | ||
/** | ||
@@ -231,3 +295,3 @@ * Run all tests. | ||
exports.test = function(callback) { | ||
testing.run([testMaxSeconds, testWSEcho], callback); | ||
testing.run([testMaxSeconds, testWSEcho, testIndexParam, testIndexParamWithBody, testIndexParamWithCallback, testIndexParamWithCallbackAndBody], callback); | ||
}; | ||
@@ -234,0 +298,0 @@ |
{ | ||
"name": "loadtest", | ||
"version": "5.0.4", | ||
"version": "5.1.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", |
@@ -606,2 +606,21 @@ [![Build Status](https://secure.travis-ci.org/alexfernandez/loadtest.svg)](http://travis-ci.org/alexfernandez/loadtest) | ||
#### `indexParamCallback` | ||
A function that would be executed to replace the value identified through `indexParam` through a custom value generator. | ||
E.g.: if URL is `http://test.com/value` and `indexParam=value` and | ||
```javascript | ||
indexParamCallback: function customCallBack() { | ||
return Math.floor(Math.random() * 10); //returns a random integer from 0 to 9 | ||
} | ||
``` | ||
then the URL could be: | ||
* http://test.com/1 (Randomly generated integer 1) | ||
* http://test.com/5 (Randomly generated integer 5) | ||
* http://test.com/6 (Randomly generated integer 6) | ||
* http://test.com/8 (Randomly generated integer 8) | ||
* ... | ||
* body will also be replaced `body:{ userid: id_value }` will be `body:{ userid: id_<value from callback> }` | ||
#### `insecure` | ||
@@ -694,3 +713,3 @@ | ||
```javascript | ||
fucntion contentInspector (result) => { | ||
function contentInspector(result) { | ||
if (result.statusCode == 200) { | ||
@@ -697,0 +716,0 @@ const body = JSON.parse(result.body) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93568
2191
858