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 59
|
import asyncio
import json
import logging
from websockets.asyncio.client import connect
from websockets.exceptions import WebSocketException
logging.basicConfig(level=logging.WARNING)
SERVER = "ws://localhost:9001"
AGENT = "websockets.asyncio"
async def get_case_count():
async with connect(f"{SERVER}/getCaseCount") as ws:
return json.loads(await ws.recv())
async def run_case(case):
async with connect(
f"{SERVER}/runCase?case={case}&agent={AGENT}",
max_size=2**25,
) as ws:
try:
async for msg in ws:
await ws.send(msg)
except WebSocketException:
pass
async def update_reports():
async with connect(
f"{SERVER}/updateReports?agent={AGENT}",
open_timeout=60,
):
pass
async def main():
cases = await get_case_count()
for case in range(1, cases + 1):
print(f"Running test case {case:03d} / {cases}... ", end="\t")
try:
await run_case(case)
except WebSocketException as exc:
print(f"ERROR: {type(exc).__name__}: {exc}")
except Exception as exc:
print(f"FAIL: {type(exc).__name__}: {exc}")
else:
print("OK")
print(f"Ran {cases} test cases")
await update_reports()
print("Updated reports")
if __name__ == "__main__":
asyncio.run(main())
|