当前位置:网站首页>Locust performance test 2 (interface request)
Locust performance test 2 (interface request)
2022-07-07 09:08:00 【Song_ Lun】
Have been to Loust With a basic understanding of , Next, you can make an interface request
One 、 Post request
The user login
According to business needs , The login interface is executed only once , stay on_start() Function to write login information
class MyTasks(TaskSet):
url = '/login'
headers = {
'Content-Type': 'application/json'}
def on_start(self):
self.data = {
"username":"admin","password":"123456"}
respon = self.client.post(self.url, headers = self.headers, data=json.dumps(self.data), name=' The user login ', verify=False, timeout=10)
resp_dict = respon.json()
# print(f' The response data is :{resp_dict}')
if respon.status_code == 200:
# Interface success
print(resp_dict['msg'])
else:
# request was aborted
respon.failure(resp_dict['msg'])
class User(HttpUser):
tasks = [MyTasks]
host = 'https://www.baidu.com'
wait_time = between(2,2) # Every time 2 Once per second
Two 、 Get request
Send mobile phone verification code
from locust import HttpUser, TaskSet, task
''' get Request interface '''
class MyTasks(TaskSet):
url = '/xxx/xxx/sendAuthCode'
headers = {
'Content-Type': 'application/json',
'Authorization': 'xxxxx'
}
def on_start(self):
print(" User initialization -- Sign in ")
@task
def get_login(self):
print(' Send verification code ...')
# Define an object property
self.query_data = {
'mobile': 1579715000}
respon = self.client.get(self.url, params = self.query_data, headers = self.headers, name=' Send verification code ', verify=False, timeout=10)
resp_dict = respon.json()
print(f' The response data is :{
resp_dict}')
边栏推荐
- Leetcode刷题记录(数组)组合总和、组合总和 II
- How long does the PMP usually need to prepare for the exam in advance?
- External interrupt to realize key experiment
- MySQL主从延迟的解决方案
- Common operating commands of Linux
- Unityshader introduction essentials personal summary -- Basic chapter (I)
- How can I apply for a PMP certificate?
- Count the number of words C language
- Do you have any certificates with high gold content?
- PMP certificate preparation experience sharing
猜你喜欢
随机推荐
Problems encountered in the use of go micro
JVM 垃圾回收 详细学习笔记(二)
How to pass the PMP Exam in a short time?
模拟卷Leetcode【普通】1609. 奇偶树
Serial port experiment - simple data sending and receiving
Simulation volume leetcode [general] 1557 The minimum number of points that can reach all points
The essence of high availability
JVM 内存结构 详细学习笔记(一)
What is the use of PMP certificate?
个人力扣题目分类记录
Output all composite numbers between 6 and 1000
E-commerce campaign Guide
C语言指针(中篇)
STM32 serial port register library function configuration method
2020 year end summary
systemd
Common operating commands of Linux
数字三角形模型 AcWing 1027. 方格取数
串口实验——简单数据收发
[chaosblade: node disk filling, killing the specified process on the node, suspending the specified process on the node]