From a79f10f10f0cf2f3ac686d6c1c59122e30cf3b8d Mon Sep 17 00:00:00 2001 From: jangko Date: Wed, 23 Jun 2021 16:09:44 +0700 Subject: [PATCH] adapt testserverclient for upcoming websocket test --- tests/testserverclient.nim | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/testserverclient.nim b/tests/testserverclient.nim index 05f2da6..6b2c245 100644 --- a/tests/testserverclient.nim +++ b/tests/testserverclient.nim @@ -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()