autocannon
autocannon copied to clipboard
Simple mode differ from requests array mode
Hey guys,
I've found a difference in the behaviour of the "simple mode" and the more customizable "requests mode".
Here is the reproducible code:
Simple mode
'use strict'
const autocannon = require('autocannon');
function verifyBody (body) {
const { Success, Result, NonSuccessMessage, Exception } = JSON.parse(body);
console.log({ Success, Result, NonSuccessMessage, Exception })
throw new Error('STOP AFTER FIRST')
}
const runningCannon = autocannon({
url: 'https://fondimatica.it/FonteNuovaAreaAderenti_Api/api/v1/Account/AbilitaAccesso',
method: 'POST',
connections: 10,
pipelining: 1,
duration: 1,
headers: {
"content-type": 'application/json',
accept: '*/*',
"content-length": 68,
},
body: '{"CodiceFiscale":"ABCABC01F01F553C","Email":"[email protected]"}',
verifyBody
}, console.log);
autocannon.track(runningCannon);
Response: 200
Requests mode
'use strict'
const autocannon = require('autocannon');
const cannon = autocannon({
url: 'https://fondimatica.it/FonteNuovaAreaAderenti_Api/api/v1/Account',
connections: 10,
pipelining: 1,
duration: 1,
requests: [
{
method: 'POST',
path: '/AbilitaAccesso',
headers: {
"content-type": 'application/json',
accept: '*/*',
"content-length": 68,
},
body: '{"CodiceFiscale":"ABCABC01F01F553C","Email":"[email protected]"}',
onResponse: (...received) => {
console.log(received)
if (received[0] === 200) {
const resp = JSON.parse(body);
console.log({ resp })
}
throw new Error('STOP AFTER FIRST')
}
},
]
}, console.log);
Response: 503
I'm using the following versions: Node: 17.5.0 NPM: 8.4.1 Autocannon: 7.9.0
Let me know if i could help with more info or it's correct and i'm missing something
I don't know! Would you like to send a PR with a fix?
Actually I'm doing some check on the httpRequestBuilder, but the two requests seems to be equal
Ok, found it.. If i use as url 'https://fondimatica.it' and path '/FonteNuovaAreaAderenti_Api/api/v1/Account/AbilitaAccesso' it works fine. Not sure if its a bug
E.g.
const cannon = autocannon({
url: 'https://fondimatica.it',
.....
requests: [
{
path: '/FonteNuovaAreaAderenti_Api/api/v1/Account/AbilitaAccesso',
.....
},
]
}, console.log);
No reason to keep this open