一、locust登录及依赖接口压力测试
需求:
1.登录
2.change 接口下发
change_acl_mode.py
# coding=utf-8 """ @Project :pachong-master @File :change_acl_mode.py @Author :gaojs @Date :2022/7/13 10:09 @Blogs : https://www.gaojs.com.cn """ from locust import HttpUser, between, task, TaskSet, tag import os # 强制去掉控制台InsecureRequestWarning import urllib3 # 随机产生UA类库 from faker import Factory urllib3.disable_warnings() class TaskTest(TaskSet): def on_start(self): """ description:每个用户执行此段代码 :return: """ # 每个用户执行此段代码 print('==================== 清理log结束,压测开始, 登录虚拟站点并且 切换mode !!!========================') # pass # 压测任务,也可以是@task(10)啥的,这个数字是代表权重,数值越大,执行的频率就越高 @task def stress_get(self): """ 请求httpbin :return: """ url = '/prx/000/http/localh/login' data = { "Content-Type": "application/x-www-form-urlencoded, charset=UTF-8", 'Connection': 'close', "method": "localdb", "uname": "test6", "pwd1": None, "pwd2": None, "pwd": "admin", "hardwareid: ": "" } randon_ua = Factory.create() ua = randon_ua.user_agent() headers = { 'User-Agent': ua } rsp = self.client.post(url=url, headers=headers, data=data, verify=False, allow_redirects=False, name='loginVsite压测') # print(rsp.status_code) assert rsp.status_code == 302 print(rsp.text) url_mode = 'https://192.168.120.65:555/prx/000/http/localhost/accessmode?modename=mode2' rsp1 = self.client.get(url=url_mode, name='访问模式切换') print(rsp1.status_code) assert rsp1.status_code == 200 # 执行并发测试后执行的动作,比如保存log等操作,查看报告http://localhost:8089/ def on_stop(self): pass class UserBehavior(HttpUser): host = '192.168.120.65:555' # 每次请求停顿时间 wait_time = between(3, 10) tasks = [TaskTest] if __name__ == "__main__": os.system("locust -f change_acl_mode.py --host=https://192.168.120.65:555 --web-host=127.0.0.1")
二、运行及报告