forked from aws-samples/eb-locustio-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
42 lines (39 loc) · 1.15 KB
/
common.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
from time import time
from locust import events
from contextlib import contextmanager, ContextDecorator
USERS = []
INVITE_CODES = []
PARTY_ROLES = [] #Host2 / Host3 / Solo / Joiner
REGION_PINGS = [50, 50, 50, 50, 50, 50]
RUNNING = {}
HAS_RUN = False
WAIT_SECONDS = 15
HEARTBEAT_REQUEST = "{\"requestId\":999,\"type\":\"PlayerSessionRpc.HeartbeatV1Request\",\"payload\":{}}"
@contextmanager
def _manual_report(name):
start_time = time()
try:
yield
except Exception as e:
events.request.fire(
request_type="pragma",
name=name,
response_time=(time() - start_time) * 1000,
response_length=0,
exception=e,
)
raise
else:
events.request.fire(
request_type="pragma",
name=name,
response_time=(time() - start_time) * 1000,
response_length=0,
exception=None,
)
def manual_report(name_or_func):
if callable(name_or_func):
# used as decorator without name argument specified
return _manual_report(name_or_func.__name__)(name_or_func)
else:
return _manual_report(name_or_func)