直接编写接口事务脚本对后台接口进行测试;有时测试须要让全部并发用户完成初始化后再进行压力测试,这就须要相似于LoadRunner中的集合点的概念,因为框架自己没有直接封装,有以下办法实现:并发
from gevent._semaphore import Semaphore 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 """ self.login() all_locusts_spawned.wait() //限制在全部用户准备完成前处于等待状态
思路:框架
经过locust得基于gevent并发得机制,引入gevent的锁的概念,代入到locust的钩子函数中,实现集合点统一并发概念函数