locust性能脚本参数化,每个用户使用不同的数据

import queue

from locust import HttpUser,task,TaskSet


class AccountTask(TaskSet):

    def on_start(self):
        self.i=0
        try:
            self.data = self.user.user_data.get()
        except queue.Empty:
            print('no data exist')
            exit(0)

    def on_stop(self):
        pass

    @task
    def account_register(self):
        print(self.data,self.i)
        self.client.post('/account/account/api/operate',json=self.data)
        self.i+=1



class AccountUser(HttpUser):

    min_wait = 1
    max_wait = 5
    tasks = [AccountTask]
    host = "https://127.0.0.1"
    user_data = queue.Queue()
    for i in range(100):
        data = {
            "username": "test%d" % i,
            "password": "pwd%d" % i,
            "email": "test%d@xxx.com" % i,
            "phone": "135%08d" % i,
        }
        user_data.put_nowait(data)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值