fix autobahn client to process multi messages test case

turn out the autobahn server not only use single echo
message for all test case, but also use multi messages
response to measure performance.
This commit is contained in:
jangko 2021-06-12 14:58:28 +07:00
parent 3634754621
commit 99d643013b
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 16 additions and 8 deletions

View File

@ -41,6 +41,7 @@ proc getCaseCount(): Future[int] {.async.} =
proc generateReport() {.async.} = proc generateReport() {.async.} =
try: try:
trace "request autobahn server to generate report"
let ws = await connectServer("/updateReports?agent=" & agent) let ws = await connectServer("/updateReports?agent=" & agent)
while true: while true:
let buff = await ws.recv() let buff = await ws.recv()
@ -55,17 +56,24 @@ proc main() {.async.} =
trace "case count", count=caseCount trace "case count", count=caseCount
for i in 1..caseCount: for i in 1..caseCount:
trace "runcase", no=i
let path = "/runCase?case=$1&agent=$2" % [$i, agent] let path = "/runCase?case=$1&agent=$2" % [$i, agent]
try: try:
let ws = await connectServer(path) let ws = await connectServer(path)
while ws.readystate != ReadyState.Closed:
# echo back # echo back
let data = await ws.recv() let data = await ws.recv()
let opCode = if ws.binary: let opCode = if ws.binary:
Opcode.Binary Opcode.Binary
else: else:
Opcode.Text Opcode.Text
if ws.readyState == ReadyState.Closed:
break
await ws.send(data, opCode) await ws.send(data, opCode)
await ws.close()
except WebSocketError as exc: except WebSocketError as exc:
error "WebSocket error", exception = exc.msg error "WebSocket error", exception = exc.msg