How to create a Locust task for a dynamic list of URLs?

吃可爱长大的小学妹 提交于 2020-01-23 09:20:06

问题


I'm trying to get timing information for all my API endpoints based on the OpenAPI JSON, so I would like to do something like this in the setup method:

for api_path in self.client.get('/api/doc/?format=openapi').json()['paths'].keys():
    self.get_[api_path] = [@task decorated method which retrieves the API path]

Or is there another way to generate tasks at runtime?


回答1:


Found it in the API docs:

def setup(self) -> None:
    for api_path in self.client.get('/api/doc/?format=openapi').json()['paths'].keys():
        self.schedule_task(self.api_task, args=[api_path])

def api_task(self, path: str) -> None:
    response = self.client.get("/api{}?limit=1000".format(path))
    assert response.status_code == HTTPStatus.OK, response.content.decode()


来源:https://stackoverflow.com/questions/54450832/how-to-create-a-locust-task-for-a-dynamic-list-of-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!