0

我正在通过 K6 运行 APIhttp.url并收到以下异常,但不确定 URL 中遗漏了什么;

export default function() {
    let url = http.get("http://test.loadimpact.com");
    let res = http.get(url);
    check(res, {
        "status was 200": (r) => r.status == 200,
        "transaction time OK": (r) => r.timings.duration < 200
    });
    sleep(1);   
}

WARN[0063] Request Failed error="Get http://test.loadimpact.com : dial tcp "ip":80: connectex: 连接尝试失败,因为连接方在一段时间后没有正确响应,或建立连接失败,因为连接的主机没有响应。”

错误 [0063] GoError: 无效 URL 值 '&http.Response{ctx:(*context.valueCtx)(0xc003dfbb00), RemoteIP:"", RemotePort:0, URL:" http://test.loadimpact.com", Status:0, Proto:"", Headers:map[string]string(nil), Cookies:map[string][]*httpext.HTTPCookie(nil), Body:interface {}(nil), Timings:httpext .ResponseTimings{Duration:0, Blocked:0,lookingUp:0, Connecting:0, TLSHandshaking:0, Sending:0, Waiting:0, Receiving:0}, TLSVersion:"", TLSCipherSuite:"", OCSP:netext。 OCSP{ProducedAt:0, ThisUpdate:0, NextUpdate:0, RevokedAt:0, RevocationReason:"", Status:""}, Error:"dial tcp "ip":80: connectex: 连接尝试失败,因为连接方一段时间后没有正确响应,或者由于连接的主机未能响应而建立连接失败。", ErrorCode:1210, Request:httpext.Request{Method:"GET", URL:" http://test.loadimpact .com ",标题:map[string][]string{"用户代理":[]string{"k6/0.24.0 ( https://k6.io/)"}},正文:"",Cookies:map[string][]*httpext.HTTPRequestCookie{}},cachedJSON:interface {}(nil),validatedJSON:false}'

4

1 回答 1

2

您将 URL 设置为http.get函数调用的结果,我认为您打算这样做:

export default function() {
  let url = "http://test.loadimpact.com";
  let res = http.get(url);
  check(res, {
    "status was 200": (r) => r.status == 200,
        "transaction time OK": (r) => r.timings.duration < 200
    });
    sleep(1);   
}
于 2019-05-30T13:33:12.517 回答