add test cases for rpc websocket client-server

This commit is contained in:
jangko 2021-06-23 18:44:14 +07:00
parent b8a8ca2623
commit ccb19734e6
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 23 additions and 0 deletions

View File

@ -32,3 +32,26 @@ suite "Socket Server/Client RPC":
srv.stop()
waitFor srv.closeWait()
suite "Websocket Server/Client RPC":
var srv = newRpcWebSocketServer("127.0.0.1", Port(8545))
var client = newRpcWebSocketClient()
srv.setupServer()
srv.start()
waitFor client.connect("ws://127.0.0.1:8545/")
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]"
test "Missing params":
expect(CatchableError):
discard waitFor client.call("myProc", %[%"abc"])
test "Error RPC call":
expect(CatchableError): # The error type wont be translated
discard waitFor client.call("myError", %[%"abc", %[1, 2, 3, 4]])
srv.stop()
waitFor srv.closeWait()