From 99d643013b07e51f7ec965c05c75303dd03843c3 Mon Sep 17 00:00:00 2001 From: jangko Date: Sat, 12 Jun 2021 14:58:28 +0700 Subject: [PATCH] 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. --- examples/autobahn_client.nim | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/examples/autobahn_client.nim b/examples/autobahn_client.nim index 341f216ed2..92ac1e5e8a 100644 --- a/examples/autobahn_client.nim +++ b/examples/autobahn_client.nim @@ -41,6 +41,7 @@ proc getCaseCount(): Future[int] {.async.} = proc generateReport() {.async.} = try: + trace "request autobahn server to generate report" let ws = await connectServer("/updateReports?agent=" & agent) while true: let buff = await ws.recv() @@ -55,17 +56,24 @@ proc main() {.async.} = trace "case count", count=caseCount for i in 1..caseCount: + trace "runcase", no=i let path = "/runCase?case=$1&agent=$2" % [$i, agent] try: let ws = await connectServer(path) - # echo back - let data = await ws.recv() - let opCode = if ws.binary: - Opcode.Binary - else: - Opcode.Text - await ws.send(data, opCode) - await ws.close() + + while ws.readystate != ReadyState.Closed: + # echo back + let data = await ws.recv() + let opCode = if ws.binary: + Opcode.Binary + else: + Opcode.Text + + if ws.readyState == ReadyState.Closed: + break + + await ws.send(data, opCode) + except WebSocketError as exc: error "WebSocket error", exception = exc.msg