python locust 性能测试:locust参数-保证并发测试数据唯一性,循环取数据,pythonlocust,from locus
python locust 性能测试:locust参数-保证并发测试数据唯一性,循环取数据,pythonlocust,from locus
from locust import TaskSet, task, HttpLocust
import queue
class UserBehavior(TaskSet):
@task
def test_register(self):
try:
# get_nowait() 取不到数据直接崩溃;get() 取不到数据会一直等待
data = self.locust.user_data_queue.get_nowait() # 取值顺序 ‘username‘: ‘test0000‘、‘username‘: ‘test0001‘、‘username‘: ‘test0002‘...
except queue.Empty: # 取不到数据时,走这里
print(‘account data run out, test ended.‘)
exit(0)
print(‘register with user: {}, pwd: {}‘.format(data[‘username‘], data[‘password‘]))
payload = {
‘username‘: data[‘username‘],
‘password‘: data[‘password‘]
}
r = self.client.post(‘/user/signin?ReturnUrl=https%3A%2F%2Fwww.cnblogs.com%2F‘, data=payload)
self.locust.user_data_queue.put_nowait(data) # 把取出来的数据重新加入队列
assert r.status_code == 200
class WebsiteUser(HttpLocust):
host = ‘https://passport.cnblogs.com‘
task_set = UserBehavior
user_data_queue = queue.Queue() # 创建队列,先进先出
for index in range(100):
data = {
"username": "test%04d" % index,
"password": "pwd%04d" % index,
"email": "test%[email protected]" % index,
"phone": "186%08d" % index,
}
user_data_queue.put_nowait(data) # 循环加入队列<全部>,循环完,继续执行
min_wait = 1000
max_wait = 3000
参考:http://debugtalk.com/post/head-first-locust-advanced-script/
python locust 性能测试:locust参数-保证并发测试数据唯一性,循环取数据
相关内容
- Python机器学习——Agglomerative层次聚类,,层次聚类(h
- python学习之----用虚拟环境保存库文件,python----,如果你
- 【Python】self的用法扫盲,pythonself扫盲,在Python中,我
- 使用python操作InfluxDB,python操作influxdb,环境: CentOS
- win10环境下python3安装sqlserver方法,win10python3,win10环境下
- python 读取文件第一列 空格隔开的数据,,file=open(
- Mac配置eclipse+pydev+Python遇到的问题,eclipsepydev,最近在研
- python算两个时间之间的天数,将天数转成int型,python
- python,random随机数的获取,pythonrandom随机数, 随机数
- 玩了下opencv的aruco(python版),opencvaruco,简单的玩了下
评论关闭