如何在K6中应用函数的迭代条件



我想一次执行登出函数,多次执行dropDown函数。我需要在下面的代码中进行哪些更改。

executors: {
logout: {
type: 'per-vu-iterations',
exec: 'logout',
vus: 1,
iterations: 1,
startTime: '30s',
maxDuration: '1m',
tags: { my_tag: 'LOGOUT'},
},
}};
export function logout() {
group('Logout API', () => {
loginFunctions.logout_api();
})
}
export function dropDown() {
group('Drop Down API', () => {
loginFunctions.dropDown_api();
})
}
export default function () {
logout();
dropDown();
}

如果没有默认功能,它也不起作用。获取执行器默认值:在导出中找不到函数"default">此错误

不确定在#1007合并并发布之前,您在哪里看到了executors,这是选项的旧名称。新的正确名称是scenarios:https://k6.io/docs/using-k6/scenarios

因此,为了回答您的问题,代码应该看起来有点像这样:

import http from 'k6/http';
import { sleep } from 'k6';
export let options = {
scenarios: {
logout: {
executor: 'per-vu-iterations',
exec: 'logout',
vus: 1, iterations: 1,
maxDuration: '1m',
tags: { my_tag: 'LOGOUT' },
},
dropDown: {
executor: 'per-vu-iterations',
exec: 'dropDown',
vus: 10, iterations: 10, // or whatever
maxDuration: '1m',
tags: { my_tag: 'LOGOUT' },
},
}
};
export function logout() {
console.log("logout()");
sleep(1);
// ...
}
export function dropDown() {
console.log("dropDown()");
sleep(1);
// ...
}

不过,根据您的用例,logout()代码的最佳位置实际上可能在teardown()生命周期函数中?看见https://k6.io/docs/using-k6/test-life-cycle有关更多详细信息,

最新更新