这是我第一次使用Locust进行负载测试。我的配置文件是:
locustfile = locustfile.py
headless = true
master = false
# expect-workers = 5
users = 200
spawn-rate = 10
run-time = 10m
tags = [Critical, Normal]
我的 locustfile.py 如下:
from locust import HttpUser, task, between
class StaticWebSite(HttpUser):
wait_time = between(1, 5)
host = "https://example.com"
@task
def index(self):
self.client.get("/")
@task
def boat(self):
self.client("/other_page")
当我执行locust时,出现以下错误:
File "/home/roland/.cache/pypoetry/virtualenvs/bnw-new-5YYRTg7r-py3.11/lib/python3.11/site-packages/locust/user/task.py", line 479, in get_next_task
raise Exception(
Exception: No tasks defined on StaticWebSite. Use the @task decorator or set the 'tasks' attribute of the User (or mark it as abstract = True if you only intend to subclass it)
显然代码有@task装饰器,所以我不知道为什么它不被识别。
在您的配置文件中,您有
tags=[Critical, Normal]
。这意味着您已将 Locust 设置为查找带有这些标签之一的任务才能运行。它将跳过带有其中任何一个标记的任何任务。您需要从配置文件中删除该行或标记您的任务。
https://docs.locust.io/en/latest/api.html#locust.env.Environment.tags https://docs.locust.io/en/latest/writing-a-locustfile.html#tag-decorator