Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

status code option #519

Open
vanodevium opened this issue Apr 4, 2024 · 11 comments
Open

status code option #519

vanodevium opened this issue Apr 4, 2024 · 11 comments

Comments

@vanodevium
Copy link

Thanks for a great tool!

It would be very useful to be able to specify which status code I want to check.

For example, I check an endpoint that always returns 302, I specify it in the option and the tool isn't "afraid" that it is not 20x.

Something like:

autocannon -c 10 --status 302 https://domain.com/return/redirect
@mcollina
Copy link
Owner

How this would be different from --renderStatusCodes?

@vanodevium
Copy link
Author

In fact, there is no difference, except that a basic report on the status code I need will be enough for me, and not a table with all the statuses.

@mcollina
Copy link
Owner

Thanks for the clarification! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@vanodevium
Copy link
Author

Of course, I'll try. And tests, 100%

@vanodevium
Copy link
Author

@mcollina

I'm sorry, but I couldn't do anything. Most likely, I just lack experience and that's why I couldn't.

The biggest problem is the non2xx calculation that is very difficult for me to change with dynamic codeIndex (it is in the printResult.js file)

non2xx: statusCodes[0] + statusCodes[2] + statusCodes[3] + statusCodes[4],

I really tried but failed.

@xt-riot
Copy link

xt-riot commented Jan 14, 2025

Hey @vanodevium,

I want to make sure I understood your request. You want each specific statusCode to be shown at the second-to-last line of the output, right?

Do you want to know the exact statusCode that has been captured, or the statusCodes per group?

Example all status codes:

Screenshot 2025-01-14 at 5 41 21 PM

Example grouped status codes:

Screenshot 2025-01-14 at 5 39 21 PM

I think the best one is the grouped status codes. Anyone that wants to know more about that can use the --renderStatusCodes argument

@vanodevium
Copy link
Author

@xt-riot

A little bit wrong. Lets me clarify:

I don't need grouping by status so much.
just the ability to tell the autocannon "the status 302 SHOULD be equated to OK" for a specific case (or any other status, 409 for example)

because in specific test case I really try to test some non2xx code

Thanx!

@xt-riot
Copy link

xt-riot commented Jan 14, 2025

Hey @vanodevium,

Can you provide a test scenario with which I can replicate it myself? Code and/or usage would be super helpful.

I'm asking because if you use autocannon programmatically in a test-suite, there is already a way to achieve what you want.

@vanodevium
Copy link
Author

@xt-riot

unfortunately, the is written in very old version of php (also code are only on remote server)

also 1000% there is no tests programmatically, just cli mode

Scenario:

I'm requesting a remote server that should return a 302 code to me.
I want to see in the terminal how many times it successfully returned a 302 (because I want to tell autocannon that 302 is success case for me in my situation), and treat everything else as a failure

@xt-riot
Copy link

xt-riot commented Jan 14, 2025

Hey @vanodevium

Does that look okay to you?

node ./autocannon.js -c 1 -d 2 --renderStatusCodes "http://localhost:3000/test3"

Screenshot 2025-01-14 at 8 20 39 PM

node ./autocannon.js -c 1 -d 2 --renderOnlyStatusCode=404 --renderStatusCodes "http://localhost:3000/test3"

Screenshot 2025-01-14 at 8 20 59 PM

node ./autocannon.js -c 1 -d 2 --renderOnlyStatusCode=200,302 --renderStatusCodes "http://localhost:3000/test3"

Screenshot 2025-01-14 at 8 21 08 PM

Note:
The second-to-last line hasn't changed.

@vanodevium
Copy link
Author

@xt-riot Looks awesome! This is enough for all needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants