I'm currently trying to stress-test a web application that allows simple user login, logout and other functionalities with wrk but am really struggling to correctly write a script that allows me to chain multiple requests together.
For example, I'd like to write a script that randomly makes a incoming thread do one of:
1.
- login
- logout
- login
- do function A
- logout
- login
- do function B
- logout
The application makes use of form-based authentication and maintains sessions. Presently, I can't even figure out how to do a correct post request to my /login route that the application understands such that the wrk thread correctly fills in a username and password to forms in the application. The application works correctly in the browser but I've been really stuck on trying to make this work in a wrk script. Currently I've tried something like:
function request_0 ()
headers = {}
headers["Content-Type"] = "multipart/form-data"
local body = '{"username": "user0", "password": "pass0"}'
return wrk.format("POST", "/login", headers, body)
end
function request_1 ()
headers = {}
headers["Content-Type"] = "multipart/form-data"
local body = '{"username": "user1", "password": "pass1"}'
return wrk.format("POST", "/login", headers, body)
end
requests = {}
requests[0] = request_0
requests[1] = request_1
request = function()
return requests[math.random(0,1)]()
end
To at least simulate multiple possible incoming requests, but my application does not register the username or password given. If anyone could provide help on the proper syntax for the requests, how to chain multiple requests together, and how to handle authentication, this would be really appreciated.