autocannon
Advanced tools
Comparing version 5.0.0 to 5.0.1
@@ -90,11 +90,2 @@ 'use strict' | ||
const emitAndMove = () => { | ||
const resp = this.resData[this.cer] | ||
this.emit('response', resp.headers.statusCode, resp.bytes, resp.duration) | ||
resp.bytes = 0 | ||
this.cer = this.cer === pipelining - 1 ? 0 : this.cer++ | ||
this.requestIterator.nextRequest() | ||
this._doRequest(this.cer) | ||
} | ||
this.parser[HTTPParser.kOnBody] = (body, start, len) => { | ||
@@ -111,11 +102,9 @@ this.emit('body', body) | ||
const resp = this.resData[this.cer] | ||
if (this.requestIterator.expectsBody()) { | ||
this.requestIterator.recordBody(resp.headers.statusCode, bodyString) | ||
emitAndMove() | ||
} | ||
this.requestIterator.recordBody(resp.req, resp.headers.statusCode, bodyString) | ||
} | ||
this.parser[HTTPParser.kOnMessageComplete] = () => { | ||
const end = process.hrtime(this.resData[this.cer].startTime) | ||
this.resData[this.cer].duration = end[0] * 1e3 + end[1] / 1e6 | ||
const resp = this.resData[this.cer] | ||
const end = process.hrtime(resp.startTime) | ||
resp.duration = end[0] * 1e3 + end[1] / 1e6 | ||
@@ -126,5 +115,6 @@ if (!this.destroyed && this.reconnectRate && this.reqsMade % this.reconnectRate === 0) { | ||
if (!this.requestIterator.expectsBody()) { | ||
emitAndMove() | ||
} | ||
this.emit('response', resp.headers.statusCode, resp.bytes, resp.duration) | ||
resp.bytes = 0 | ||
this.cer = this.cer === pipelining - 1 ? 0 : this.cer++ | ||
this._doRequest(this.cer) | ||
} | ||
@@ -178,2 +168,6 @@ | ||
this.emit('request') | ||
if (this.reqsMade > 0) { | ||
this.requestIterator.nextRequest() | ||
} | ||
this.resData[rpi].req = this.requestIterator.currentRequest | ||
this.resData[rpi].startTime = process.hrtime() | ||
@@ -180,0 +174,0 @@ this.conn.write(this.getRequestBuffer()) |
@@ -84,9 +84,5 @@ 'use strict' | ||
RequestIterator.prototype.expectsBody = function () { | ||
return this.currentRequest && typeof this.currentRequest.onResponse === 'function' | ||
} | ||
RequestIterator.prototype.recordBody = function (status, body) { | ||
if (this.expectsBody()) { | ||
this.currentRequest.onResponse(status, body, this.context) | ||
RequestIterator.prototype.recordBody = function (request, status, body) { | ||
if (request && typeof request.onResponse === 'function') { | ||
request.onResponse(status, body, this.context) | ||
} | ||
@@ -93,0 +89,0 @@ } |
{ | ||
"name": "autocannon", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "Fast HTTP benchmarking tool written in Node.js", | ||
@@ -5,0 +5,0 @@ "main": "autocannon.js", |
@@ -549,6 +549,9 @@ 'use strict' | ||
{ | ||
body: 'hello world again', | ||
body: 'hello world!', | ||
onResponse: (status, body) => responses.push({ status, body }) | ||
}, | ||
{ | ||
body: 'hello world again' | ||
}, | ||
{ | ||
method: 'GET', | ||
@@ -567,8 +570,12 @@ onResponse: (status, body) => responses.push({ status, body }) | ||
t.same(client.getRequestBuffer(), | ||
Buffer.from(`POST / HTTP/1.1\r\nHost: localhost:${server.address().port}\r\nConnection: keep-alive\r\nContent-Length: 17\r\n\r\nhello world again`), | ||
Buffer.from(`POST / HTTP/1.1\r\nHost: localhost:${server.address().port}\r\nConnection: keep-alive\r\nContent-Length: 12\r\n\r\nhello world!`), | ||
'first request') | ||
t.deepEqual(responses, [{ | ||
status: 200, | ||
body: 'hello!' | ||
}]) | ||
break | ||
case 2: | ||
t.same(client.getRequestBuffer(), | ||
Buffer.from(`GET / HTTP/1.1\r\nHost: localhost:${server.address().port}\r\nConnection: keep-alive\r\n\r\n`), | ||
Buffer.from(`POST / HTTP/1.1\r\nHost: localhost:${server.address().port}\r\nConnection: keep-alive\r\nContent-Length: 17\r\n\r\nhello world again`), | ||
'second request') | ||
@@ -578,2 +585,11 @@ t.deepEqual(responses, [{ | ||
body: 'hello!' | ||
}]) | ||
break | ||
case 3: | ||
t.same(client.getRequestBuffer(), | ||
Buffer.from(`GET / HTTP/1.1\r\nHost: localhost:${server.address().port}\r\nConnection: keep-alive\r\n\r\n`), | ||
'third request') | ||
t.deepEqual(responses, [{ | ||
status: 200, | ||
body: 'hello!' | ||
}, { | ||
@@ -583,2 +599,17 @@ status: 200, | ||
}]) | ||
break | ||
case 4: | ||
t.same(client.getRequestBuffer(), | ||
Buffer.from(`POST / HTTP/1.1\r\nHost: localhost:${server.address().port}\r\nConnection: keep-alive\r\nContent-Length: 12\r\n\r\nhello world!`), | ||
'first request') | ||
t.deepEqual(responses, [{ | ||
status: 200, | ||
body: 'hello!' | ||
}, { | ||
status: 200, | ||
body: 'world!' | ||
}, { | ||
status: 200, | ||
body: 'hello!' | ||
}]) | ||
client.destroy() | ||
@@ -585,0 +616,0 @@ t.end() |
@@ -214,10 +214,10 @@ 'use strict' | ||
const iterator = new RequestIterator(opts) | ||
iterator.recordBody(200, 'ok') | ||
iterator.recordBody(iterator.currentRequest, 200, 'ok') | ||
iterator.nextRequest() | ||
iterator.recordBody(500, 'ignored') | ||
iterator.recordBody(iterator.currentRequest, 500, 'ignored') | ||
iterator.nextRequest() | ||
iterator.recordBody(201, '') | ||
iterator.recordBody(iterator.currentRequest, 201, '') | ||
// will reset the iterator | ||
iterator.nextRequest() | ||
iterator.recordBody(200, 'ok') | ||
iterator.recordBody(iterator.currentRequest, 200, 'ok') | ||
}) | ||
@@ -224,0 +224,0 @@ |
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
431101
4084