forked from SvenskaSpel/locust-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection_pool_ex.py
47 lines (36 loc) · 1.32 KB
/
connection_pool_ex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from locust import HttpUser, FastHttpUser, task
from locust_plugins.connection_pools import FastHttpPool, RequestPool
class RequestPoolExample(HttpUser):
"""HttpUser using requestPool"""
def on_start(self):
self.pool = RequestPool(user=self)
# Alternatively, you can override the client attribute of the user
# but if you have any type checking tools setup they will complain
# self.client = RequestPool(user=self) # type: ignore
@task
def task_1(self):
"""example task"""
self.pool.get(url="/")
# self.client.get(url="/foo/bar")
@task
def task_2(self):
"""example task"""
payload = {"bin": "baz"}
self.pool.post(url="/foo/bar", data=payload)
# self.client.get(url="/foo/bar", data=payload)
class FastHttpPoolExample(FastHttpUser):
"""FastHttpUser using"""
def on_start(self):
self.pool = FastHttpPool(user=self)
# self.client = FastHttpPool(user=self) # type: ignore
@task
def task_1(self):
"""example task"""
self.pool.get(path="/")
# self.client.get(url="/foo/bar")
@task
def task_2(self):
"""example task"""
payload = {"bin": "baz"}
self.pool.post(path="/foo/bar", data=payload)
# self.client.get(url="/foo/bar", data=payload)