存储过程:
create procedure insertuser(num int)
begin
declare i int;
set i=0;
while i<=num do
insert into iwebshop_user(username,password) values(concat("ll",i),"96e79218965eb72c92a549dd5a330112");
set i=i+1;
end while;
end
基本语法:
from locust import HttpUser,task,TaskSet
class UserBehavior(TaskSet):
@task
def test_login(self):
logindata={"login_info":"ll",
"password":"123456"}
self.client.post("/index.php?controller=simple&action=login_act",data=logindata)
class WebsiteUser(HttpUser):
host = "http://localhost/iwebshop"
tasks=[UserBehavior]
min_wait = 1000
max_wait = 5000
## for循环:
```python
from locust import HttpUser,task,TaskSet
class UserBehavior(TaskSet):
@task
def test_login(self):
for i in range(0,101):
username="ll"+str(i)
logindata={"login_info":username,
"password":"111111"}
self.client.post("/index.php?controller=simple&action=login_act",data=logindata)
class WebsiteUser(HttpUser):
host="http://localhost/iwebshop"
tasks=[UserBehavior]
min_wait = 1000
max_wait = 5000
从csv读取:
from locust import HttpUser,task,TaskSet
import csv
class UserBehavior(TaskSet):
@task
def test_login(self):
file=open("login.csv","r")
table=csv.reader(file)
for row in table:
login_data={"login_info":row[0],
"password":row[1]}
self.client.post("/index.php?controller=simple&action=login_act",data=login_data)
class WebsiteUser(HttpUser):
host = "http://localhost/iwebshop"
tasks = [UserBehavior]
min_wait = 1000
max_wait = 5000
设置集合体,同时并发
from gevent._semaphore import Semaphore
all_locusts_spawned = Semaphore()
all_locusts_spawned.acquire()
class UserBehavior_mycount(TaskSet):
def on_start(self):
all_locusts_spawned.wait()
设置任务权重
不指定权重,默认为1:1
方法一:
@task(1)
@task(2)
方法二:
tasks={方法一:1,方法二:2}