feat: port locust to use GRPC payloads
This commit is contained in:
parent
69172db518
commit
565ffec3c6
1 changed files with 28 additions and 28 deletions
|
@ -1,4 +1,5 @@
|
||||||
import json
|
import json
|
||||||
|
import grpc
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from locust import FastHttpUser, between, task
|
from locust import FastHttpUser, between, task
|
||||||
|
|
||||||
|
@ -103,17 +104,38 @@ import gevent
|
||||||
import adaptor
|
import adaptor
|
||||||
from locust import events, task
|
from locust import events, task
|
||||||
|
|
||||||
|
host = "localhost:9001"
|
||||||
|
captcha_id = "locust"
|
||||||
|
|
||||||
|
|
||||||
|
def add_captcha(stub: DcacheServiceStub, captcha_id: str):
|
||||||
|
msg = dcache.AddCaptchaRequest(
|
||||||
|
id=captcha_id,
|
||||||
|
mcaptcha=dcache.MCaptcha(
|
||||||
|
duration=30,
|
||||||
|
defense=dcache.Defense(
|
||||||
|
levels=[
|
||||||
|
dcache.Level(visitor_threshold=50, difficulty_factor=500),
|
||||||
|
dcache.Level(visitor_threshold=5000, difficulty_factor=50000),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
resp = stub.AddCaptcha(msg)
|
||||||
|
pprint(f"Captcha added {captcha_id}: {resp}")
|
||||||
|
|
||||||
|
|
||||||
|
with grpc.insecure_channel(host) as channel:
|
||||||
|
stub = DcacheServiceStub(channel)
|
||||||
|
add_captcha(stub=stub, captcha_id=captcha_id)
|
||||||
|
|
||||||
|
|
||||||
class HelloGrpcUser(adaptor.GrpcUser):
|
class HelloGrpcUser(adaptor.GrpcUser):
|
||||||
stub_class = DcacheServiceStub
|
stub_class = DcacheServiceStub
|
||||||
leader = "localhost:9001"
|
host = host
|
||||||
host = leader
|
captcha_id = captcha_id
|
||||||
captcha_id = "locust"
|
|
||||||
msg = RaftRequest(data=json.dumps({"AddVisitor": captcha_id}))
|
msg = RaftRequest(data=json.dumps({"AddVisitor": captcha_id}))
|
||||||
|
|
||||||
def on_start(self):
|
|
||||||
self.add_captcha(captcha_id=self.captcha_id)
|
|
||||||
|
|
||||||
def add_vote(self, captcha_id: str):
|
def add_vote(self, captcha_id: str):
|
||||||
resp = self.stub.Write(self.msg)
|
resp = self.stub.Write(self.msg)
|
||||||
|
|
||||||
|
@ -121,28 +143,6 @@ class HelloGrpcUser(adaptor.GrpcUser):
|
||||||
# resp = self.pipeline_write(data=self.pipeline_vote)
|
# resp = self.pipeline_write(data=self.pipeline_vote)
|
||||||
# pprint(resp)
|
# pprint(resp)
|
||||||
|
|
||||||
def add_captcha(self, captcha_id: str):
|
|
||||||
params = {
|
|
||||||
"AddCaptcha": {
|
|
||||||
"id": captcha_id,
|
|
||||||
"mcaptcha": {
|
|
||||||
"visitor_threshold": 0,
|
|
||||||
"defense": {
|
|
||||||
"levels": [
|
|
||||||
{"visitor_threshold": 50, "difficulty_factor": 500},
|
|
||||||
{"visitor_threshold": 5000, "difficulty_factor": 50000},
|
|
||||||
],
|
|
||||||
"current_visitor_threshold": 0,
|
|
||||||
},
|
|
||||||
"duration": 30,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
msg = RaftRequest(data=json.dumps(params))
|
|
||||||
resp = self.stub.Write(msg)
|
|
||||||
pprint(f"Captcha added {captcha_id}: {resp}")
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def addVote(self):
|
def addVote(self):
|
||||||
self.add_vote(self.captcha_id)
|
self.add_vote(self.captcha_id)
|
||||||
|
|
Loading…
Add table
Reference in a new issue