k6 - 配置文件中的 tlsAuth 和 *.crt 文件

k6 - tlsAuth in config file with *.crt files

查询与 k6 工具中的以下配置选项相关:

  1. tlsAuth - 如何传递保存在 config.json 文件中另一个文件夹中的证书。
  2. minIterationDuration 选项在 k6 中如何工作?请就 config.json 文件中的语法提出建议。

我已尝试在 config.json 中为这两个查询设置如下配置。

  1. 对于 tlsAuth,不能将 'open' 放在 json 文件中,如下所示。那么解决方法是什么?

  2. 试图了解 minIterationDuration 配置选项。如果默认函数早于这个定义的持续时间完成执行,k6 是否等待?在另一种情况下,当默认函数完成执行的时间超过这个定义的持续时间时,它是否不等待?

下面是 config.json 文件的片段 ->(实际文件也有更多选项)

{
"tlsAuth": [{ 
    "domains": ["example.com"], 
    "cert": open(".\certs\mycert.pem"),
    "key": open(".\certs\mycert-key.pem")
  }],
"minIterationDuration":20
}

期望通过配置文件定义我所有的 k6 选项,包括 tlsAuth 选项,并使用另一个文件夹中定义的证书。不想在主 js 文件中定义 k6 选项。

请指教。提前致谢,如果这是一个简单的编码级别问题,我深表歉意。

从更简单的问题开始:

Trying to understand minIterationDuration config option. Does k6 wait if default function completes execution earlier than this defined duration?

In the other scenario, does it wait for no time when default function completes execution in more time than this defined duration?

是的。如果你用它的调整单位定义 minIterationDuration ,它会更具可读性,比如 "2s""400ms".

For tlsAuth, cannot put 'open' in the json file as below. So what is the work around?

那个JSON文件是一个简单的数据文件,里面不能有像open()这样的函数。 open() 只能在 k6 执行的 JS 脚本中工作——它只是读取文件内容,默认情况下 returns 它们作为字符串。所以,如果你想要 JSON 配置中的 tlsAuth 选项,你必须将它指定为一个字符串,尽管它是一个非常大的字符串。

Do not want to define k6 options in the main js file.

您可以采用混合方法。您可以将大部分配置放在一个简单的 JSON 或 JS 文件中,open()import 放在主 JS 文件中,然后将其再次导出为脚本 options:


export let options = JSON.parse(open("my-custom-config.json"))
options.tlsAuth = open("/some/other/file")