Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

autocannon

Package Overview
Dependencies
Maintainers
3
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

autocannon - npm Package Compare versions

Comparing version 7.8.1 to 7.9.0

samples/customise-verifyBody-workers.js

2

autocannon.js

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

onPort: false,
url: url
url
})

@@ -252,0 +252,0 @@ const tracker = initJob(opts, () => {

@@ -94,6 +94,2 @@ 'use strict'

if (!this.destroyed) {
if (this.opts.expectBody && this.opts.expectBody !== resp.body) {
return this.emit('mismatch', resp.body)
}
this.requestIterator.recordBody(resp.req, resp.headers.statusCode, resp.body, resp.headers.headers)

@@ -104,2 +100,9 @@

this._doRequest()
const isFn = typeof this.opts.verifyBody === 'function'
if (isFn && !this.opts.verifyBody(resp.body)) {
return this.emit('mismatch', resp.body)
} else if (!isFn && this.opts.expectBody && this.opts.expectBody !== resp.body) {
return this.emit('mismatch', resp.body)
}
}

@@ -106,0 +109,0 @@ }

'use strict'
// given we support node v8
// eslint-disable-next-line node/no-deprecated-api
// eslint-disable-next-line n/no-deprecated-api
const { parse } = require('url')

@@ -6,0 +6,0 @@

@@ -59,3 +59,3 @@ 'use strict'

if (url.indexOf('http') !== 0) url = 'http://' + url
url = URL.parse(url) // eslint-disable-line node/no-deprecated-api
url = URL.parse(url) // eslint-disable-line n/no-deprecated-api

@@ -69,2 +69,3 @@ // copy over fields so that the client

url.setupClient = opts.setupClient
url.verifyBody = opts.verifyBody
url.timeout = opts.timeout

@@ -128,8 +129,8 @@ url.origin = `${url.protocol}//${url.host}`

samples,
errors: errors,
timeouts: timeouts,
mismatches: mismatches,
errors,
timeouts,
mismatches,
non2xx: statusCodes[0] + statusCodes[2] + statusCodes[3] + statusCodes[4],
statusCodeStats,
resets: resets,
resets,
duration: Math.round((Date.now() - startTime) / 10) / 100,

@@ -136,0 +137,0 @@ start: new Date(startTime),

@@ -28,14 +28,15 @@ 'use strict'

const setupClient = opts.workers ? opts.setupClient : safeRequire(opts.setupClient)
const verifyBody = opts.workers ? opts.verifyBody : safeRequire(opts.verifyBody)
const requests = opts.requests
? opts.requests.map((r) => {
const setupRequest = opts.workers ? r.setupRequest : safeRequire(r.setupRequest)
const onResponse = opts.workers ? r.onResponse : safeRequire(r.onResponse)
const setupRequest = opts.workers ? r.setupRequest : safeRequire(r.setupRequest)
const onResponse = opts.workers ? r.onResponse : safeRequire(r.onResponse)
return {
...r,
...(setupRequest ? { setupRequest } : undefined),
...(onResponse ? { onResponse } : undefined)
}
})
return {
...r,
...(setupRequest ? { setupRequest } : undefined),
...(onResponse ? { onResponse } : undefined)
}
})
: undefined

@@ -47,2 +48,3 @@

...(setupClient ? { setupClient } : undefined),
...(verifyBody ? { verifyBody } : undefined),
...(requests ? { requests } : undefined)

@@ -83,2 +85,6 @@ }

if (!isValidFn(opts.verifyBody)) {
return new Error('Invalid option verifyBody, please provide a function (or file path when in workers mode)')
}
if (!checkURL(opts.url) && !opts.socketPath) {

@@ -85,0 +91,0 @@ return new Error('url or socketPath option required')

@@ -33,8 +33,9 @@ 'use strict'

...(opts.setupClient ? { setupClient: require(opts.setupClient) } : undefined),
...(opts.verifyBody ? { verifyBody: require(opts.verifyBody) } : undefined),
requests: opts.requests
? opts.requests.map(r => ({
...r,
...(r.setupRequest ? { setupRequest: require(r.setupRequest) } : undefined),
...(r.onResponse ? { onResponse: require(r.onResponse) } : undefined)
}))
...r,
...(r.setupRequest ? { setupRequest: require(r.setupRequest) } : undefined),
...(r.onResponse ? { onResponse: require(r.onResponse) } : undefined)
}))
: undefined,

@@ -41,0 +42,0 @@ histograms: {

{
"name": "autocannon",
"version": "7.8.1",
"version": "7.9.0",
"description": "Fast HTTP benchmarking tool written in Node.js",

@@ -47,3 +47,3 @@ "main": "autocannon.js",

"split2": "^4.0.0",
"standard": "^16.0.3",
"standard": "^17.0.0",
"tap": "^16.0.0"

@@ -50,0 +50,0 @@ },

@@ -266,2 +266,3 @@ ![banner](autocannon-banner.png)

setupClient: '/full/path/to/setup-client.js',
verifyBody: '/full/path/to/verify-body.js'
requests: [

@@ -303,2 +304,3 @@ {

* `setupClient`: A `Function` which will be passed the `Client` object for each connection to be made. This can be used to customise each individual connection headers and body using the API shown below. The changes you make to the client in this function will take precedence over the default `body` and `headers` you pass in here. There is an example of this in the samples folder. _OPTIONAL_ default: `function noop () {}`. When using `workers`, you need to supply a file path that default exports a function instead (Check out the [workers](#workers) section for more details).
* `verifyBody`: A `Function` which will be passed the `Client` object for each connection to be made. This can be used to customise the validation rules for response body. This function will take precedence over the `expectBody` you pass in here. There is an example of this in the samples folder. When using `workers`, you need to supply a file path that default exports a function instead (Check out the [workers](#workers) section for more details).
* `maxConnectionRequests`: A `Number` stating the max requests to make per connection. `amount` takes precedence if both are set. _OPTIONAL_

@@ -305,0 +307,0 @@ * `maxOverallRequests`: A `Number` stating the max requests to make overall. Can't be less than `connections`. `maxConnectionRequests` takes precedence if both are set. _OPTIONAL_

@@ -28,3 +28,3 @@ 'use strict'

autocannon({
url: url,
url,
// connection number should n times of the number of server

@@ -31,0 +31,0 @@ connections: 2,

@@ -18,6 +18,6 @@ 'use strict'

autocannon({
url: url,
url,
connections: 1000,
duration: 10,
setupClient: setupClient
setupClient
}, finishedBench)

@@ -24,0 +24,0 @@

@@ -22,3 +22,3 @@ 'use strict'

autocannon({
url: url,
url,
connections: 1,

@@ -25,0 +25,0 @@ amount: 1,

@@ -18,3 +18,3 @@ 'use strict'

const instance = autocannon({
url: url,
url,
connections: 1000,

@@ -21,0 +21,0 @@ duration: 10

@@ -23,3 +23,3 @@ 'use strict'

autocannon({
url: url,
url,
duration: 2,

@@ -26,0 +26,0 @@ workers: 2,

@@ -22,3 +22,3 @@ 'use strict'

autocannon({
url: url,
url,
requests: [

@@ -25,0 +25,0 @@ {

@@ -18,3 +18,3 @@ 'use strict'

autocannon({
url: url,
url,
connections: 1000,

@@ -21,0 +21,0 @@ duration: 10,

@@ -18,3 +18,3 @@ 'use strict'

autocannon({
url: url,
url,
connections: 1000,

@@ -21,0 +21,0 @@ duration: 10,

@@ -68,3 +68,3 @@ 'use strict'

t.doesNotThrow(() => build({ method: method }), `${method} should be usable by the request builded`)
t.doesNotThrow(() => build({ method }), `${method} should be usable by the request builded`)
})

@@ -71,0 +71,0 @@ t.end()

@@ -330,2 +330,38 @@ 'use strict'

test('run should produce count of mismatches with verifyBody set', (t) => {
t.plan(2)
initJob({
url: 'http://localhost:' + server.address().port,
verifyBody: function () {
return false
},
maxOverallRequests: 10,
timeout: 100
}, function (err, result) {
t.error(err)
t.equal(result.mismatches, 10)
t.end()
})
})
test('run should produce 0 mismatches with verifyBody set and return true', (t) => {
t.plan(2)
const responseBody = 'hello dave'
const server = helper.startServer({ body: responseBody })
initJob({
url: 'http://localhost:' + server.address().port,
verifyBody: function (body) {
return body.indexOf('hello') > -1
},
maxOverallRequests: 10
}, function (err, result) {
t.error(err)
t.equal(result.mismatches, 0)
t.end()
})
})
test('run should accept a unix socket/windows pipe', (t) => {

@@ -332,0 +368,0 @@ t.plan(11)

@@ -139,2 +139,32 @@ 'use strict'

test('verifyBody work with workers', { skip: !hasWorkerSupport }, (t) => {
const server = http.createServer((req, res) => {
// it's not easy to assert things within setupRequest and onResponse
// when in workers mode. So, we set something in onResponse and use in the
// next Request and make sure it exist or we return 404.
if (req.method === 'GET' && req.url !== '/test-123?some=thing&bar=baz') {
res.statusCode = 404
res.end('NOT OK')
return
}
res.end('OK')
})
server.listen(0)
server.unref()
initJob({
url: 'http://localhost:' + server.address().port,
connections: 2,
amount: 4,
workers: 1,
verifyBody: path.join(__dirname, './utils/verify-body')
}, function (err, result) {
t.error(err)
t.equal(4, result.mismatches, 'should have 4 mismatches requests')
t.end()
})
})
test('setupClient works with workers', { skip: !hasWorkerSupport }, (t) => {

@@ -141,0 +171,0 @@ const server = http.createServer((req, res) => {

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