python - 蝗虫忽略扩展子类并实例化基类
问题描述
我想编写基本 http 用户类和基本负载测试形状,然后在子类中扩展它们,但 locust 不理解扩展类和 instatiate bas 类,这些是基类 helpers.py:
from locust.contrib.fasthttp import FastHttpUser
import string
from locust import LoadTestShape, constant_pacing
from dotenv import load_dotenv
import os
load_dotenv()
# init parameters
host_address = "127.0.0.1"
class BaseHttpUser(FastHttpUser):
host = host_address
wait_time = constant_pacing(5)
chars = string.ascii_uppercase + string.ascii_lowercase + string.digits
start_time = 0
class BaseRps(LoadTestShape):
time_limit = 600
user_spawn = {1: (1500, 10)}
def tick(self):
step = len(self.user_spawn.keys())
run_time = self.get_run_time()
print(step, )
for idx in range(1, step+1):
print(run_time , idx , self.time_limit)
if run_time < idx * self.time_limit / step:
print("here", self.user_spawn.get(idx))
return self.user_spawn.get(idx)
return None
这是我运行 minio.py 的文件
from locust import task
from helpers import BaseHttpUser, BaseRps
import os
host_address = "127.0.0.1"
test_name = "minio"
log_file_path = 'log.log'
base_url = os.getenv("MINIO_URL")
class HttpUser(BaseHttpUser):
host = host_address
base_url = base_url
@task
def download(self):
self.client.get(f'{self.base_url}/magnix-server-media/ads-images/ff.png', name='download')
class Rps(BaseRps):
user_spawn = {1: (10000, 100)}
解决方案
基本用户类需要一个abstract = True
不被实例化的属性。https://docs.locust.io/en/stable/api.html#locust.User.abstract
我不认为你可以对负载形状类做同样的事情,但你可以使用类属性(你可以在导入之后在你的 locustfile 中操作)
就像删除 Rps 类,而只是做
BaseRps.user_spawn = {1: (10000, 100)}
推荐阅读
- java - 使用 JDBC 和 MySQL 插入 1000 条具有关系的记录并忽略重复项
- r - 在 R 中逐行累积
- python - 根据另一个 df python pandas 更新 df 列值
- python - 在 python 中遍历 SQL 表
- apache - 如果存在具有特定值的标头,则使用 .htaccess 仅允许请求
- java - 在 Servlet 中生成线程
- maven - artifactId Selenium-java.jar 从 3.3.1 更改为 3.4 导致我的 maven 项目中出现大量“无法访问”错误
- performance - 如何分解scala.js JS输出的大小
- entity-framework - 实体框架使用参数执行存储过程
- javascript - 一年后,仍然在单元测试、集成测试和 E2E 测试中苦苦挣扎