第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

性能測試-Locust腳本加強篇(關(guān)聯(lián)、檢查點、集合點)

標(biāo)簽:
Python 性能測試

1、关联:通常在业务流程中有很多一系列的接口调用,从后面的接口依赖前边接口的结果数据

from lxml import etree
from locust import TaskSet, task, HttpUser
class UserBehavior(TaskSet):
    @staticmethod
    def get_session(html):
        tree = etree.HTML(html)
        return tree.xpath("http://div[@class='btnbox']/input[@name='session']/@value")[0] \
    @task(10)
    def test_login(self):
        html = self.client.get('/login').text
        username = 'user@compay.com'
        password = '123456'
        session = self.get_session(html)
        payload = { 'username': username, 'password': password, 'session': session }
        self.client.post('/login', data=payload)

class WebsiteUser(HttpUser):
    host = 'http://debugtalk.com'
    # task_set = UserBehavior
    tasks = [UserBehavior ]
    min_wait = 1000
    max_wait = 3000

2、检查点:用来判断返回值是否符合要求

from lxml import etree
from locust import TaskSet, task, HttpUser
class UserBehavior(TaskSet):
    @staticmethod
    def get_session(html):
        tree = etree.HTML(html)
        return tree.xpath("http://div[@class='btnbox']/input[@name='session']/@value")[0] \
    @task(10)
    def test_login(self):
        html = self.client.get('/login').text
        assert "200" in html
        username = 'user@compay.com'
        password = '123456'
        session = self.get_session(html)
        payload = { 'username': username, 'password': password, 'session': session }
        self.client.post('/login', data=payload)

class WebsiteUser(HttpUser):
    host = 'http://debugtalk.com'
    # task_set = UserBehavior
    tasks = [UserBehavior ]
    min_wait = 1000
    max_wait = 3000

3、集合点:提高某个接口的并发度,当所有用户运行到指定位置后集合等待,同时向下执行

from gevent._semaphore import Semaphore
from locust import TaskSet, events
from lxml import etree

all_locusts_spawned = Semaphore()
all_locusts_spawned.acquire()
def on_hatch_complete(**kwargs):
    all_locusts_spawned.release() # 创建钩子方法

events.hatch_complete += on_hatch_complete # 挂载到locust钩子函数(所有的Locust实例产生完成时触发)

class TestTask(TaskSet):
    def on_start(self):
        """ on_start is called when a Locust start before any task is scheduled """
        all_locusts_spawned.wait() # 限制在所有用户准备完成前处于等待状态
        self.login()

    @staticmethod
    def get_session(html):
        tree = etree.HTML(html)
        return tree.xpath("http://div[@class='btnbox']/input[@name='session']/@value")[0] \

    def login(self):
        html = self.client.get('/login').text
        username = 'user@compay.com'
        password = '123456'
        session = self.get_session(html)
        payload = {'username': username, 'password': password, 'session': session}
        self.client.post('/login', data=payload)

个人博客 蜗牛

點擊查看更多內(nèi)容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學(xué)

大額優(yōu)惠券免費領(lǐng)

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消