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 48 49 50 51 52 53 54 55 56 57 58
|
"""
This Molotov script uses events to generate a success/failure output
"""
import json
import time
import molotov
_T = {}
def _now():
return time.time() * 1000
@molotov.events()
async def record_time(event, **info):
if event == "scenario_start":
scenario = info["scenario"]
index = (info["wid"], scenario["name"])
_T[index] = _now()
if event == "scenario_success":
scenario = info["scenario"]
index = (info["wid"], scenario["name"])
start_time = _T.pop(index, None)
duration = int(_now() - start_time)
if start_time is not None:
print(
json.dumps(
{
"ts": time.time(),
"type": "scenario_success",
"name": scenario["name"],
"duration": duration,
}
)
)
elif event == "scenario_failure":
scenario = info["scenario"]
exception = info["exception"]
index = (info["wid"], scenario["name"])
start_time = _T.pop(index, None)
duration = int(_now() - start_time)
if start_time is not None:
print(
json.dumps(
{
"ts": time.time(),
"type": "scenario_failure",
"name": scenario["name"],
"exception": exception.__class__.__name__,
"errorMessage": str(exception),
"duration": duration,
}
)
)
|