Skip to content

Commit

Permalink
Merge pull request #1982 from BonelessPi/master
Browse files Browse the repository at this point in the history
Fire requests through Environment.events
  • Loading branch information
cyberw authored Jan 26, 2022
2 parents 5951ea4 + 6f960b8 commit f4c2541
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions examples/grpc/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def run_grpc_server(environment, **_kwargs):


class GrpcClient:
def __init__(self, stub):
def __init__(self, environment, stub):
self.env = environment
self._stub_class = stub.__class__
self._stub = stub

Expand All @@ -47,7 +48,7 @@ def wrapper(*args, **kwargs):
except grpc.RpcError as e:
request_meta["exception"] = e
request_meta["response_time"] = (time.perf_counter() - start_perf_counter) * 1000
events.request.fire(**request_meta)
self.env.events.request.fire(**request_meta)
return request_meta["response"]

return wrapper
Expand All @@ -66,7 +67,7 @@ def __init__(self, environment):
self._channel = grpc.insecure_channel(self.host)
self._channel_closed = False
stub = self.stub_class(self._channel)
self.client = GrpcClient(stub)
self.client = GrpcClient(environment, stub)


class HelloGrpcUser(GrpcUser):
Expand Down

0 comments on commit f4c2541

Please sign in to comment.