当前位置:网站首页>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}')
边栏推荐
- How can I apply for a PMP certificate?
- 9c09730c0eea36d495c3ff6efe3708d8
- H3C VXLAN配置
- 寄存器地址名映射
- Several methods of calculating the average value of two numbers
- 数字三角形模型 AcWing 1027. 方格取数
- Digital triangle model acwing 275 Pass a note
- Systick滴答定时器
- 【ChaosBlade:节点 CPU 负载、节点网络延迟、节点网络丢包、节点域名访问异常】
- Storage of data in memory
猜你喜欢
Panel display technology: LCD and OLED
Esp32-ulp coprocessor low power mode RTC GPIO interrupt wake up
Three updates to build applications for different types of devices | 2022 i/o key review
外部中断实现按键实验
Digital triangle model acwing 1027 Grid access
Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022
Calf problem
STM32的时钟系统
Storage of data in memory
Common short chain design methods
随机推荐
平台化,强链补链的一个支点
C语言指针(特别篇)
How does the project manager write the weekly summary and weekly plan?
硬件大熊原创合集(2022/06更新)
【Istio Network CRD VirtualService、Envoyfilter】
【ChaosBlade:根据标签删除POD、Pod 域名访问异常场景、Pod 文件系统 I/O 故障场景】
How to pass the PMP Exam in a short time?
Vagrant failed to mount directory mount: unknown filesystem type 'vboxsf'
实现自定义内存分配器
How can I apply for a PMP certificate?
Golang etcdv3 reports an error. The attribute in grpc does not exist
Common operating commands of Linux
PMP Exam details after the release of the new exam outline
LeetCode 736. LISP syntax parsing
MAC OSX php dyld: Library not loaded: /usr/local/xxxx. dylib
STM32的时钟系统
PMP Exam Preparation experience systematically improve project management knowledge through learning
How to use Arthas to view class variable values
[istio introduction, architecture, components]
What is the use of PMP certificate?