Locust用2xx做了响应,但未能收集请求统计信息。

问题描述 投票:0回答:1

我正在尝试用Locust做一个本地负载测试。我得到了测试环境并运行,本地构建也在工作。我试图测试一个本地路径的响应,我在终端中得到的响应是正确的。但是Locust的UI和终止测试后的统计都给我100%的失败结果。

对于创建蝗虫的代码(我对它很陌生),我使用postman的内容并调整了它。这是蝗虫的代码。

from locust import HttpLocust, TaskSet, task, between 
import requests

url = "http://localhost:8080/registry/downloadCounter"
payload = "[\n    {\n        \"appName\": \"test-app\",\n        \"appVersion\": \"1.6.0\"\n    }\n]"

class MyTaskSet(TaskSet):

    @task(2)
    def index(self):
        self.client.get("")
        headers = {
        'Content-Type': 'application/json',
        'Accept':'application/json'
        }
        response = requests.request("POST", url, headers=headers, data = payload)

        print(response.text.encode('utf8'))

class MyLocust(HttpLocust):
    task_set = MyTaskSet
    wait_time = between(2.0, 4.0)

对于蝗虫群,我只用了基本的数字:模拟的总用户数。1孵化率: 3主机: http:/localhost:8080registrydownloadCounter。

我在那里没有得到任何结果,表格一直是空白的。我猜这和json格式有关,但我自己也找不到解决办法。

我还把终止后终端响应的截图放在这个帖子里。

先谢谢你的帮助

衷心感谢

enter image description here

http automated-tests http-post load-testing locust
1个回答
0
投票

这帮助了我。

from locust import HttpLocust, TaskSet, task, between 
import requests

url = "http://localhost:8080/registry/downloadCounter"
payload = "[\n    {\n        \"appName\": \"test-app\",\n        \"appVersion\": \"1.6.0\"\n    }\n]"
headers = {'Content-type':'application/json', 'Accept':'application/json'}

class MyTaskSet(TaskSet):

    @task(2)
    def index(self):
        response = self.client.post(url = url, data = payload, headers=headers)

        print(response.text.encode('utf8'))
        print(response.status_code)


class MyLocust(HttpLocust):
    task_set = MyTaskSet
    wait_time = between(2.0, 4.0)
```
© www.soinside.com 2019 - 2024. All rights reserved.