将 userId 与 Gatling DSL 结合使用

Using userId with Gatling DSL

我正在使用 session.userId 来参数化我的测试请求,如下所示:

exec(http("get request")
  .get((s:Session) => "somebaseUrl/" + s.userId.toString ))

是否有可能以不同的方式获取 sesion userId,这样我的请求地址就更干了,例如,我不必使用 lambda?

我尝试使用加特林 DSL:

exec(http("get request")
  .get("somebaseUrl/${userId}")

但后来我得到:No attribute named 'userId' is defined错误

我可以为我的测试计算一些随机 ID,但为什么 gatling 已经这样做了。

我想出的唯一解决方案是将 userId 保存到一些不同的属性,如下所示:

exec((s:Session) => s.set("user_id",s.userId)),
exec(http("test").get("${user_id}"))

但这似乎不对,您必须确保在所有其他请求之前调用集合。

userId是一些内部细节。 Gatling Expression语言只暴露Session属性,即属性Map内容。

要么使用您描述的第一种方式,使用函数,要么不使用 Gatling 内部结构并设置您自己的 UUID 属性(feeder、exec(function) 等)。

为避免使用加特林机内部构件,您可以使用进纸器:

var userId = 0
feed(Iterator.continually(Map("userId" -> {
      userId += 1
      userId}.toString)))