Python Third-party Library Locust Stress Test

One : The code is as follows
# coding=utf-8
"""
Author: Jianshuai guy
Function:
new features:
Date: 2022/2/23 17:25
"""
from locust import HttpUser , between, task, TaskSet
import os
from common.agCli import *
import logging


class TaskTest ( TaskSet , CLI):

# Perform concurrent pre-actions, such as cleaning up all current sessions
def on_start (self):
"""
description: log in ag, clean up log
:return :
"""
self.ssh_ag ( ) _
self.clear_log ( )
logging.info('Clearing logs is over, stress testing starts !!!')

#Pressure test task , it can also be @task(10) or something, this number represents the weight, the larger the value, the higher the execution frequency
@task
def login(self):
url = '/prx/000/http/localh/login'
data = {
"method": "http1",
"uname": "gaojs",
"pwd1": "",
"pwd2": "",
"pwd": "admin",
"submitbutton": "Sign"
}
header = {"Content-Type": "application/ json;charset =UTF-8"}
self.client.request (method='POST', url = url , data=data, headers=header, name='login to virtual site', verify=False, allow_redirects =False)

# Execute the actions performed after the concurrent test, such as saving the log, etc., view the report http://localhost:8089/
def on_stop (self):
self.ssh_ag ( ) _
self.cli_cmd ( 'switch vsite ' )
self.cli_cmd ( ' session kill all')
logging.info('Clear session is over, stress test is over , please check report, http://localhost:8089!!!')


class Login( HttpUser ):
host = 'https://192.168.120.206'
# pause time per request
wait_time = between( 1, 3)
tasks = [ TaskTest ]


if __name__ == "__main__":
os.system ("locust -f locust_test.py --host=https://192.168.120.206")
Two: The report is as follows

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00