如何用蝗虫对阿波罗服务器进行负载测试?

时间:2019-06-05 08:49:48

标签: python-3.x graphql load-testing apollo locust

有人知道如何对Apollo服务器进行负载测试吗?

 class UserBehavior(TaskSet):
        def on_start(self):
            self.login()

        @task
        def login(self):
            headers = {"content-type": "application/json"}
            self.client.post("/", data=json.dumps({
            "query": "mutation { login(username:\"9849999983\", password: \"123456\") {  token User { id fullName "
                     "email phoneNumber } } } "
            },
                headers=headers))


    class ApolloSample(HttpLocust):
        host = "https://sampleurl.com/api"
        min_wait = 20000
        max_wait = 50000
        task_set = UserBehavior

与此有关的问题是,self.client.post("/")方法中没有要保留的特定端点。由于Graphql基本上由查询和突变组成。

1 个答案:

答案 0 :(得分:1)

以下内容适用于GraphQL查询和变异。不要错过接受标题

查询

response = self.client.post(
            "http://localhost:5424/graphql",
            name="GraphQL",
            headers={
                "Accept": "application/graphql",
                "Authorization": "<Authorization-Token>"
            },
            json={"query": "<Your-GraphQL-Query>" }
        )

突变

response = self.client.post(
            "http://localhost:5424/graphql",
            name="GraphQL",
            headers={
                "Accept": "application/graphql",
                "Authorization": "<Authorization-Token>"
            },
            json={"query": "<Your-GraphQL-Query>,"
                  "operationName": "<Operation-Name>,
                  "variables":"<Input-Variables>" }
        )