locust性能测试:关联(六)

2021-09-30  本文已影响0人  HC2
from locust import HttpUser,TaskSet,between,task
import os,sys
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
PathProject = os.path.split(rootPath)[0]
sys.path.append(rootPath)
sys.path.append(PathProject)


n = 0

class UserBehavior(TaskSet):

    def login(self):
        global n
        n += 1
        return n


    def on_start(self):
        self.token = self.login()

    @task(4)
    def test1(self):
        """
        用户浏览首页商品列表
        :return:
        """

        url = '/list?token=' + str(self.token)
        param={}
        with self.client.get(url,params=param,headers={},catch_response = True) as response:
            print("用户浏览首页商品列表")



class WebsiteUser(HttpUser):
    host = 'http://127.0.0.1'
    tasks = [UserBehavior]

    wait_time = between(1, 2)
image.png

每个虚拟用户的请求都关联上了token

上一篇下一篇

猜你喜欢

热点阅读