更新使用 if Locust v1.5.3 时遇到问题
Having trouble updating to use if Locust v1.5.3
我使用的是旧版本的 Locust (V1.4.3),我想升级到最新的 V1.5.3。
我的测试环境有点不稳定,所以我必须直接指示成功或失败。这是我在旧版本中使用的代码
def RunTask(self, kind, name, task):
# Run indicated smoke test container command
start = time()
code, logs = RunTestTask(self.environment, kind, name, task)
total = time() - start
# Tell locust the resuslts
test = "{0}-{1}:{2}".format(kind, splitext(name)[0], task)
if code:
self.client.request_failure.fire(request_type = "runtask",
name = test,
response_time = total,
response_length = 0,
exception = None)
else:
self.client.request_success.fire(request_type = "runtask",
name = test,
response_time = total,
response_length = 0)
最新版本已弃用 request_failure 和 request_success 已弃用。新版本统一了两者的请求方式,但我一直没弄清楚如何正确指示成功或失败。
如有任何帮助,我们将不胜感激。
使用 request.fire 的异常参数的任何真值来指示失败。您基本上可以用
替换整个 if-block
self.environment.events.request.fire(
request_type="runtask",
name=test,
response_time=total,
response_length=0,
exception=code,
context={},
)
长话短说:新方法仅使用异常字段来区分成功和失败。这有点奇怪,但无论如何都发生在内置用户中(不可能在 HttpUser 中毫无例外地报告失败)。所以我觉得没必要加一个额外的参数来表示成功或者失败。
我使用的是旧版本的 Locust (V1.4.3),我想升级到最新的 V1.5.3。
我的测试环境有点不稳定,所以我必须直接指示成功或失败。这是我在旧版本中使用的代码
def RunTask(self, kind, name, task):
# Run indicated smoke test container command
start = time()
code, logs = RunTestTask(self.environment, kind, name, task)
total = time() - start
# Tell locust the resuslts
test = "{0}-{1}:{2}".format(kind, splitext(name)[0], task)
if code:
self.client.request_failure.fire(request_type = "runtask",
name = test,
response_time = total,
response_length = 0,
exception = None)
else:
self.client.request_success.fire(request_type = "runtask",
name = test,
response_time = total,
response_length = 0)
最新版本已弃用 request_failure 和 request_success 已弃用。新版本统一了两者的请求方式,但我一直没弄清楚如何正确指示成功或失败。
如有任何帮助,我们将不胜感激。
使用 request.fire 的异常参数的任何真值来指示失败。您基本上可以用
替换整个 if-blockself.environment.events.request.fire(
request_type="runtask",
name=test,
response_time=total,
response_length=0,
exception=code,
context={},
)
长话短说:新方法仅使用异常字段来区分成功和失败。这有点奇怪,但无论如何都发生在内置用户中(不可能在 HttpUser 中毫无例外地报告失败)。所以我觉得没必要加一个额外的参数来表示成功或者失败。