组目前不返回其持续时间。
在这种情况下发射意味着如果您使用 json output/influxdb/stastsd/load Impact 的云进行指标存储,而不是发送该组持续时间的指标,您可以稍后......从指标存储中做任何您想做的事情.
的语法check
也
check(variable_name_to_use, map_of_name_to_function_to_calls)
很像
check(group.duraiton, {
"checking duration is less than 20 as normal function": function(d){ return d<20},
"checking duration is less than 20 as arrow function": (d)=>{ return d<20},
"checking duration is less than 20 as arrow function without the brackets": (d)=>d<20,
})
使用时,您还需要提供 url 的方案http.*
。
我还想指出,这个想法group
是衡量给定组(!)的请求或操作需要多少。例如,它们可用于对包含“登录”、“将商品添加到购物车”、“结帐和付款”等所有操作进行分组。它们绝对有用,但是当您的所有组都是单个请求时将单个请求分组不会添加任何新数据:)
解决方案1:
您可以自己这样做:
import { check, group } from "k6";
import http from 'k6/http';
export default function() {
var group_duration;
group('Home page', function(){
var start = new Date();
http.get('http://localhost:8080');
group_duration = new Date() - start;
});
check(group_duration, {
"Name of group check": function(d){return d<200}
})
group('search page', function(){
var start = new Date();
http.get('http://localhost:8080/Search?term=mysearch');
group_duration = new Date() - start;
})
console.log(group_duration);
check(group_duration, {
"Name of group check": (d)=>d<200
})
}
您当然可以将其移至一个函数,并将持续时间返回为:
function mygroup(name, f) {
var start = new Date();
group(name, f);
return new Date() - start;
}
而不是打电话mygroup
并获得持续时间
var group_duration = mygroup('Home page', function(){
http.get('http://localhost:8080');
});
解决方案 2:
在您在每个组中仅使用一个请求的情况下,您可以使用请求确实返回他们花费了多少的事实。所以
resp = http.get("google.com");
check (resp.timings.duration, {
"check response time", (d) => d<200
});
将检查给定请求的时间是否少于 200 毫秒。您可以在文档中查看响应中的更多内容
作为一名 k6 开发人员,我认为您提出的建议不是一个坏主意,如果您真的打开一个问题,我想