【问题标题】:How to run test in sequential order in loadimpact?如何在loadimpact中按顺序运行测试?
【发布时间】:2018-11-22 08:58:09
【问题描述】:

我们有 2 个 API 想要测试负载影响,而第二个 API 是所谓的动态目标,它建立在我们从第一个 API 的响应中获得的数据的基础上。

因此,我们希望按顺序运行此测试。我们怎样才能做到这一点?

import { check, sleep } from 'k6';
import http from 'k6/http';

    export default function() {
            let res, res_body, claim_url
            res = http.batch([req])
            check(res[0], {
                 "form data OK": function (res) {
                        console.log(res.status);
                        claim_url = JSON.parse(res.body)
                        console.log(claim_url.details.claim_uri)
                        return false;
                 }
    });

在不同的函数中对不同的 API 进行分组有帮助吗?

【问题讨论】:

    标签: k6


    【解决方案1】:

    在任何情况下,您都不限于每次默认函数迭代的单个 http 请求。因此,您可以使用之前请求中的任何内容并执行新请求。

    http.post documentation 中有一个例子,但这里有另一个简单的例子:

    import { check, sleep } from 'k6';
    import http from 'k6/http';
    
    export default function() {
            let res, res_body, claim_url
            res = http.get(req);
    
            check(res, { // check that we actually didn't get error when getting the url
                      "response code was 200": (res) => res.status == 200,
                 });
            claim_url = JSON.parse(res.body) // if the body is "http://example.org" for example
            res2 = http.get(claim_url); // use the returned url
            check(res2, { // here it's res2 not res
                      "response code was 200": (res) => res.status == 200,
                 });
            // do more requests or checks
    
    });
    

    【讨论】:

    • 我也在考虑这个方法,但是第二个函数会在第一次完成执行之前等待吗?
    • 是的。 k6 在每一行上阻塞并等待它完成。目前没有 Promise 或 async/await 支持
    猜你喜欢
    • 2015-12-21
    • 2015-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多