即使使用正确的 "tasks" 语法,也没有在 GraphQLLocust 上定义任务

No tasks defined on GraphQLLocust even with correct "tasks" syntax

我使用的是locust版本:1.5.3;蝗虫-graphql-客户端:https://github.com/DesignrKnight/locust-graphql-client

我的目标是使用 Locust 调用 graphql 来评估性能。 我有以下蝗虫代码:

from locust import HttpUser, TaskSet, task
from locustgraphqlclient import GraphQLLocust


class UserBehavior(TaskSet):
    def on_start(self):
        """ on_start is called when a Locust start before any task is scheduled """
        self.login()

    def on_stop(self):
        """ on_stop is called when the TaskSet is stopping """
        self.logout()

    def login(self):
        query = '''
        mutation login($username: String!, $password: String!) {
          login(username: $username, password: $password) {
            access_token
          }
        }'''
        variables = {
            'username': 'gm',
            'password': 'centric8'
        }
        result = self.client.execute("login", query, variables)

        # Inject the Access Token in the Client, so subsequent requests can be made
        self.client.inject_token(result['data']['login']['access_token'])

    def logout(self):
        # Reset the Access Token in the Client, so no subsequent requests can be made
        self.client.inject_token('')

    @task(2)
    def index(self):
        query = '''
                    query products {
                      products {
                        id
                        name
                        image
                      }
                    }'''
        result = self.client.execute("products", query)

    @task(1)
    def profile(self):
        query = '''
                    query me {
                      me {
                        id
                        username
                        firstName
                        lastName                    
                      }
                    }'''
        result = self.client.execute("me", query)


class WebsiteUser(GraphQLLocust):
    tasks = [UserBehavior]
    min_wait = 5000
    max_wait = 9000

我得到如下错误

Traceback (most recent call last):
  File "~/venv/lib/python3.8/site-packages/locust/user/task.py", line 285, in run
    self.schedule_task(self.get_next_task())
  File "/~/venv/lib/python3.8/site-packages/locust/user/task.py", line 417, in get_next_task
    raise Exception(
Exception: No tasks defined on GraphQLLocust. use the @task decorator or set the tasks property of the User (or mark it as abstract = True if you only intend to subclass it)

如您所见,我对任务使用了正确的语法,如下所述:locust 0.9 to 1.3 Exception: No tasks defined. use the @task decorator or set the tasks property of the User and here https://github.com/locustio/locust/issues/1537

是不是我用的locust graphql客户端有问题?还是代码中的内容? 还有我可以在蝗虫中用于 graphql 的任何标准客户端吗?

Locust 正在尝试实例化您的基础 class。通过设置 abstract = True.

标记 GraphQLLocust class 摘要