1. 程式人生 > >locust手機號批量註冊效能測試

locust手機號批量註冊效能測試

from locust import TaskSet,task,HttpLocust
from common.redisCon import redis_clusters
import queue


class register(TaskSet):
    @task
    def register(self):
        data = {}
        data['name'] = '龍雄'
        data['idcard'] = '430922199110063124'
        data['carnum'] = '湘A7X72J'
        data['pwd
'] = 'bcb15f821479b4d5772bd0ca866c00ad5f926e3580720659cc80d39c9d09802a' self.data = data try: phone = self.locust.telqueue.get() except: print("no data exist") exit(0) header = { "Accept": "application/json, text/plain, */*" } json
= {"address": {"province": "陝西省", "country": "陝西省西安市碑林區雁塔北路4號靠近陝西工藝美術館(金都國際大廈)", "city": "西安市"}, "password": self.data['pwd'], "vehicleType": "{\"isCertificate\":\"有證\",\"isCold\":\"\",\"isElectric\":\"\",\"isTailBoard\":\"帶尾板\",\"length\":\"9.6米\",\"name\":\"廂式貨車\"}
", "registerChannel": "android", "userType": "driver", "usualRunArea": "陝西省,西安市,碑林區", "name": self.data['name'], "phone": phone, "verifyCode": '888888', "plateNum": self.data['carnum'], "idcardNum": self.data['idcard'] } r = self.client.post('/driver/security/regist',headers=header,json=json,verify=False) print("=========================================================================================") print(json) print(r.text) assert r.status_code == 200 class test_run(HttpLocust): host = 'http://192.168.xx.xx' task_set = register phonelist = list(str(18800002000 + i) for i in range(0, 100)) redis_clusters(int(phonelist[0]), int(phonelist[99])) # print(phonelist) telqueue = queue.Queue() for i in phonelist: telqueue.put_nowait(i) if __name__ == "__main__": import os os.system("locust -f register.py")

 

 

1、執行該程式;
2、訪問localhost:8089,設定虛擬使用者數,與每秒使用者併發數,確定後執行

 


3、locust會自動生成測試報告