gpt4 book ai didi

python-3.x - 如何使用 Locust 对 apollo 服务器进行负载测试?

转载 作者:行者123 更新时间:2023-12-02 12:43:21 24 4
gpt4 key购买 nike

有人知道如何对 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 基本上由查询和变异组成。

最佳答案

以下内容适用于 GraphQL 查询和突变。不要错过接受 header

查询

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>" }
)

关于python-3.x - 如何使用 Locust 对 apollo 服务器进行负载测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56457139/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com