autocannon icon indicating copy to clipboard operation
autocannon copied to clipboard

Simple mode differ from requests array mode

Open bortolottidev opened this issue 2 years ago • 3 comments

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

bortolottidev avatar Aug 04 '22 08:08 bortolottidev

I don't know! Would you like to send a PR with a fix?

mcollina avatar Aug 04 '22 20:08 mcollina

Actually I'm doing some check on the httpRequestBuilder, but the two requests seems to be equal

bortolottidev avatar Aug 05 '22 17:08 bortolottidev

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);

bortolottidev avatar Aug 05 '22 18:08 bortolottidev

No reason to keep this open

bortolottidev avatar May 16 '23 22:05 bortolottidev