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/

最新文章

  1. travis CI
  2. CAS代理配置
  3. 简单的html和css
  4. javascript 函数详解2 -- arguments
  5. 我常用的Mac快捷键
  6. JS魔法堂:获取当前脚本文件的绝对路径
  7. 重新想象 Windows 8.1 Store Apps 系列文章索引
  8. 一款基于css3的3D图片翻页切换特效
  9. POJ2104 K-th Number Range Tree
  10. Guava学习
  11. cookie防篡改
  12. C++传递函数指针
  13. OCP-1Z0-051-名称解析-文章7称号
  14. PHP版本的区别
  15. Python爬虫通过替换http request header来欺骗浏览器实现登录
  16. PLSQL Developer图形化界面新建用户并授权并导入脚本
  17. svn eclipse链接
  18. UOJ.179.线性规划(单纯形)
  19. 基础系列(4)—— C#装箱和拆箱
  20. 重大新闻:腾讯大杀器来了,QQ浏览器微信版推出

热门文章

  1. java web service 写入图片到web/img/
  2. npm太慢, 修改npm镜像
  3. Centos7.6 安装DNS服务器
  4. 关于Kafka区分请求处理优先级的讨论
  5. python学习中的bug
  6. Go语言基础之数组
  7. [LeetCode] Longest Substring Without Repeating Characters 最长无重复字符的子串
  8. char 与 varchar 区别
  9. 45道sql
  10. C++11 std::call_once:保证函数在任何情况下只调用一次