【发布时间】:2020-11-11 23:47:26
【问题描述】:
我一直在阅读 K6 文档,并且正在努力寻找一种方法来使 K6 脚本符合我的需求。我脑海中想象的场景:
// 1. init code
export function setup() {
// 2. setup code
// The VU would get setup here with authentication once
}
export default function (data) {
// 3. VU code
// The VU would run this code a repeated amount of times
}
export function teardown(data) {
// 4. teardown code
// The VU would be deauthed here after the VU code has ran its course
不幸的是,根据我在这里读到的内容:https://k6.io/docs/using-k6/test-life-cycle,我的理解是上述情况是不可能的。 "setup 在测试开始时调用,在 init 阶段之后但在 VU 阶段(默认函数)之前,在测试结束时,在 VU 阶段(default 函数)之后调用teardown。因此, 在执行setup 和teardown 函数时,VU 编号为 0。”我将此解释为,在上述场景中,所有 VU 将使用相同的身份验证来运行 VU 代码,而不是每个 VU 都获得自己单独的身份验证。
如果我简单地排除设置和拆卸部分,那么每个 VU 都会在每个循环中获得新的身份验证:
export default function (data) {
// 3. VU code
// VU gets authenticated
// VU does a bunch of stuff
// VU clears authentication
}
有没有办法按照我的意图设计 K6 脚本(VU Authenticates once -> VU code loop -> Deauth at the end once)?
【问题讨论】:
标签: testing load-testing k6