我需要使用wrk对我们的系统进行基准测试,但遇到了问题。如何使用lua在wrk中链接请求?
场景
Lua脚本:
json = require "json"
log = require "log"
counter=100
access_token = ""
request = function()
path="/api/v1/auth"
wrk.headers["x-auth-devicemetadata"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
wrk.headers["x-auth-user"] = "test_user_"..counter
wrk.headers["x-auth-pass"] = "test_password"
wrk.headers["Content-Type"] = "application/json"
wrk.headers["x-auth-deviceuid"] = "test:chrome"
counter = counter + 1
return wrk.format("POST", path, headers)
end
response = function(status, headers, body)
if status >= 400 then
log.debug("user id: "..counter)
log.debug("https status": ..status)
log.debug("Error body: "..body)
return
end
if status == 200 then
log.debug("Successfull: "..body)
log.debug("User: "..counter)
autorization = json.decode(body)
access_token = autorization["access_token"]
end
end
.....
# GET data from X endpoint
# GET data from Y endpoint
我的主要问题是如何使用lua在wrk脚本中链接请求并在它们之间传递数据?