adapt testserverclient for upcoming websocket test

This commit is contained in:
jangko 2021-06-23 16:09:44 +07:00
parent 22c342bcc1
commit a79f10f10f
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 14 additions and 12 deletions

View File

@ -2,20 +2,22 @@ import
unittest, json, chronicles,
../json_rpc/[rpcclient, rpcserver]
var srv = newRpcSocketServer(["localhost:8545"])
var client = newRpcSocketClient()
# Create RPC on server
srv.rpc("myProc") do(input: string, data: array[0..3, int]):
return %("Hello " & input & " data: " & $data)
proc setupServer*(srv: RpcServer) =
srv.rpc("myProc") do(input: string, data: array[0..3, int]):
return %("Hello " & input & " data: " & $data)
srv.rpc("myError") do(input: string, data: array[0..3, int]):
raise (ref ValueError)(msg: "someMessage")
srv.rpc("myError") do(input: string, data: array[0..3, int]):
raise (ref ValueError)(msg: "someMessage")
srv.start()
waitFor client.connect("localhost", Port(8545))
suite "Socket Server/Client RPC":
var srv = newRpcSocketServer(["localhost:8545"])
var client = newRpcSocketClient()
srv.setupServer()
srv.start()
waitFor client.connect("localhost", Port(8545))
suite "Server/Client RPC":
test "Successful RPC call":
let r = waitFor client.call("myProc", %[%"abc", %[1, 2, 3, 4]])
check r.getStr == "Hello abc data: [1, 2, 3, 4]"
@ -28,5 +30,5 @@ suite "Server/Client RPC":
expect(CatchableError): # The error type wont be translated
discard waitFor client.call("myError", %[%"abc", %[1, 2, 3, 4]])
srv.stop()
waitFor srv.closeWait()
srv.stop()
waitFor srv.closeWait()