nim-json-rpc/tests/testserverclient.nim

28 lines
758 B
Nim
Raw Normal View History

import ../ rpcclient, ../ rpcserver
import unittest, asyncdispatch, json
2018-03-02 11:46:59 +00:00
var srv = newRpcServer()
2018-04-24 13:43:04 +01:00
srv.address = "localhost"
srv.port = Port(8545)
proc makeProc(server: RpcServer) =
server.rpc("myProc") do(input: string, data: array[0..3, int]):
result = %("Hello " & input & " data: " & $data)
2018-04-12 18:51:06 +01:00
2018-04-12 19:29:48 +01:00
asyncCheck srv.serve
2018-04-24 13:43:04 +01:00
srv.makeProc
suite "Server/Client RPC":
2018-04-24 13:50:56 +01:00
proc main {.async.} =
var client = newRpcClient()
await client.connect("localhost", Port(8545))
2018-04-24 13:50:56 +01:00
test "Custom RPC":
# Custom async RPC call
var response = waitFor client.call("myProc", %[%"abc", %[1, 2, 3, 4]])
2018-04-24 19:22:16 +01:00
check response.result.getStr == "Hello abc data: [1, 2, 3, 4]"
2018-04-26 19:37:19 +01:00
# TODO: When an error occurs during a test, stop the server
asyncCheck main()
2018-04-24 13:50:56 +01:00