zoukankan      html  css  js  c++  java
  • python locust 性能测试:locsut参数化-保证并发测试数据唯一性,不循环取数据

    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']))
    body = {
    'username': data['username'],
    'password': data['password']
    }
    r = self.client.post('/user/signin', data=body).text
    assert r.status_code == 200


    class WebsiteUser(HttpLocust):
    host = 'https://passport.cnblogs.com'
    task_set = UserBehavior
    user_data_queue = queue.Queue(maxsize=100) # 创建队列,先进先出
    for index in range(100):
    data = {
    "username": "test%04d" % index,
    "password": "pwd%04d" % index,
    "email": "test%04d@debugtalk.test" % 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/
  • 相关阅读:
    content type
    存储过程查询并插入到临时表
    jdk 生成证书
    sql 表值函数-将一个传入的字符串用2中分隔符拆分成临时表
    sql 把一个用逗号分隔的多个数据字符串变成一个表的一列
    sql 分隔字符串函数
    md5 加密
    SQL语句的使用
    WINDOW的cmd的命令【转载】
    zookeeper安装
  • 原文地址:https://www.cnblogs.com/changqing8023/p/9563355.html
Copyright © 2011-2022 走看看