tsenart / vegeta

HTTP load testing tool and library. It's over 9000!
http://godoc.org/github.com/tsenart/vegeta/lib
MIT License
23.51k stars 1.36k forks source link

form post #496

Closed tcurdt closed 4 years ago

tcurdt commented 4 years ago

I need to test an endpoint that receives input from a form. I am generating the input json like this

jq -ncM 'while(true; .+1) | {method: "POST", url: "http://localhost:8080/s/1", body: {a: . | "\(.)-some" } }'
...
{"method":"POST","url":"http://localhost:8080/s/1","body":{"a":"21375-some"}}
...

As documented in the README I tried to stream this into

jq -ncM 'while(true; .+1) | {method: "POST", url: "http://localhost:8080/s/1", body: {a: . | "\(.)-some" } }' | \
vegeta attack -rate=50/s -lazy -format=json -duration=30s | tee results.bin | vegeta report

but what I am getting as output (pretty much immediately - not after 30s)

Requests      [total, rate, throughput]         3, 81.66, 0.00
Duration      [total, attack, wait]             36.78ms, 36.737ms, 43.034µs
Latencies     [min, mean, 50, 90, 95, 99, max]  43.034µs, 309.894µs, 164.507µs, 722.142µs, 722.142µs, 722.142µs, 722.142µs
Bytes In      [total, mean]                     0, 0.00
Bytes Out     [total, mean]                     0, 0.00
Success       [ratio]                           0.00%
Status Codes  [code:count]                      0:3  
Error Set:
parse error: expected string near offset 59 of 'body'

I guess it's sending json instead of form encoding? But I still don't understand the error message.

tsenart commented 4 years ago

Try to @base64 encode the body with jq.

Sent via Superhuman iOS ( https://sprh.mn/?vip=tsenart@gmail.com )

On Mon, Mar 2 2020 at 1:07 AM, < notifications@github.com > wrote:

I need to test an endpoint that receives input from a form. I am generating the input json like this

jq -ncM 'while(true; .+1) | {method: "POST", url: "http://localhost:8080/s/1", body: {a: . | "(.)-some" } }' ... {"method":"POST","url":"http://localhost:8080/s/1","body":{"a":"21375-some"}} ...

As documented in the README I tried to stream this into

jq -ncM 'while(true; .+1) | {method: "POST", url: "http://localhost:8080/s/1", body: {a: . | "(.)-some" } }' | \ vegeta attack -rate=50/s -lazy -format=json -duration=30s | tee results.bin | vegeta report

but what I am getting as output (pretty much immediately - not after 30s)

Requests [total, rate, throughput] 3, 81.66, 0.00 Duration [total, attack, wait] 36.78ms, 36.737ms, 43.034µs Latencies [min, mean, 50, 90, 95, 99, max] 43.034µs, 309.894µs, 164.507µs, 722.142µs, 722.142µs, 722.142µs, 722.142µs Bytes In [total, mean] 0, 0.00 Bytes Out [total, mean] 0, 0.00 Success [ratio] 0.00% Status Codes [code:count] 0:3 Error Set: parse error: expected string near offset 59 of 'body'

I guess it's sending json instead of form encoding? But I still don't understand the error message.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub ( https://github.com/tsenart/vegeta/issues/496?email_source=notifications&email_token=AAAQPD4232D7FOYAQFCBXJTRFL2D7A5CNFSM4K7JWY62YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IRRE67Q ) , or unsubscribe ( https://github.com/notifications/unsubscribe-auth/AAAQPDZNYWCAMSXH3336D4DRFL2D7ANCNFSM4K7JWY6Q ).

tcurdt commented 4 years ago

That's slightly better. But it does not send

Content-Type: application/x-www-form-urlencoded

This is how the request looks like:

POST /s/1 HTTP/1.1
Host: localhost.charlesproxy.com:8080
User-Agent: Go-http-client/1.1
Content-Length: 29
X-Vegeta-Seq: 45
Accept-Encoding: gzip

{"a":"21375-some"}

But it should look likes this:

POST /s/1 HTTP/1.1
Host: localhost.charlesproxy.com:8080
User-Agent: curl/7.64.1
Accept: */*
Content-Length: 48
Content-Type: application/x-www-form-urlencoded
Connection: keep-alive

a=21375-some
tsenart commented 4 years ago

There's no built-in conversion of the JSON body field to URL encoded format. You might have some success using the HTTP target format instead.

tcurdt commented 4 years ago

That's a bit of a shame. Would be nice if this could be done through the JSON. But I just managed to get it working by adding manually encoding it and setting the header like this

vegeta attack -header "Content-Type: application/x-www-form-urlencoded" ...
tsenart commented 4 years ago

Cool! Happy this is sorted out :-)