post调用的LocustIO测试结果

2024-09-21 03:21:29 发布

您现在位置:Python中文网/ 问答频道 /正文

post call如何与LOcustIO合作?我怀疑Locust没有做它应该做的事情,因为它返回了我正在运行的所有负载测试的成功,所以我决定发布,通过一个使用LocustIO的web应用程序写入DB,令我惊讶的是没有写入DB。虽然我知道有些人已经成功地做到了这一点,但我想知道如何使用ocastio编写数据库,作为负载测试的一部分。你知道吗

使用的代码如下:

from locust import HttpLocust, TaskSet, task
import logging, sys
from credentials import *

class LoginWithUniqueUsersSteps(TaskSet):
    institutionCode = "NOT_FOUND"
    username = "NOT_FOUND"
    password = "NOT_FOUND"

    def on_start(self):
            if len(USER_CREDENTIALS) > 0:
               self.institutionCode, self.username, self.password = USER_CREDENTIALS.pop()

    @task
    def login(self):
        self.client.post("/dejavuweb/", {
           'institutionCode': self.institutionCode, 'email': self.username, 'password': self.password
        })
        logging.info('Login with %s institutionCode %s username and %s password', self.institutionCode, self.username, self.password)

    @task
    def createTerminal(self):
        response = self.client.request(method="POST", url="/dejavuweb/Home#Function/7", data= {"TerminalName": "RealterminalName"})
        print("Create; Response status code:", response.status_code)
        print("Create; Response content:", response.content)

class LoginWithUniqueUsersTest(HttpLocust):
    task_set = LoginWithUniqueUsersSteps
    host = "http://dev.trublend.cloud"
    sock = None

    def __init__(self):
        super(LoginWithUniqueUsersTest, self).__init__()

请注意,我复制、编辑了上面的代码片段以实现我想要的。你知道吗

LocustIO结果截图:

Test result of LocustIO


Tags: 代码fromimportselftaskdbresponsedef

热门问题