diff --git a/json_rpc/servers/httpserver.nim b/json_rpc/servers/httpserver.nim index 59a98e8..4b10bc5 100644 --- a/json_rpc/servers/httpserver.nim +++ b/json_rpc/servers/httpserver.nim @@ -319,3 +319,8 @@ proc close*(server: RpcHttpServer) = ## Cleanup resources of RPC server. for item in server.servers: item.close() + +proc closeWait*(server: RpcHttpServer) {.async.} = + ## Cleanup resources of RPC server. + for item in server.servers: + await item.closeWait() diff --git a/json_rpc/servers/socketserver.nim b/json_rpc/servers/socketserver.nim index 8d7cc89..65869a1 100644 --- a/json_rpc/servers/socketserver.nim +++ b/json_rpc/servers/socketserver.nim @@ -146,4 +146,9 @@ proc stop*(server: RpcSocketServer) = proc close*(server: RpcSocketServer) = ## Cleanup resources of RPC server. for item in server.servers: - item.close() \ No newline at end of file + item.close() + +proc closeWait*(server: RpcSocketServer) {.async.} = + ## Cleanup resources of RPC server. + for item in server.servers: + await item.closeWait() diff --git a/tests/testerrors.nim b/tests/testerrors.nim index 7fe4d46..237c824 100644 --- a/tests/testerrors.nim +++ b/tests/testerrors.nim @@ -6,11 +6,11 @@ import unittest, debugclient, ../json_rpc/rpcserver import strformat, chronicles -var server = newRpcSocketServer("localhost", 8547.Port) +var server = newRpcSocketServer("localhost", Port(8545)) var client = newRpcSocketClient() server.start() -waitFor client.connect("localhost", Port(8547)) +waitFor client.connect("localhost", Port(8545)) server.rpc("rpc") do(a: int, b: int): result = %(&"a: {a}, b: {b}") diff --git a/tests/testethcalls.nim b/tests/testethcalls.nim index fc112ff..deb0177 100644 --- a/tests/testethcalls.nim +++ b/tests/testethcalls.nim @@ -7,7 +7,7 @@ from strutils import rsplit template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0] var - server = newRpcSocketServer("localhost", Port(8546)) + server = newRpcSocketServer("localhost", Port(8545)) client = newRpcSocketClient() ## Generate Ethereum server RPCs @@ -49,7 +49,7 @@ proc testSigCalls: Future[seq[string]] = result = all(version, sha3) server.start() -waitFor client.connect("localhost", Port(8546)) +waitFor client.connect("localhost", Port(8545)) suite "Local calls": @@ -74,4 +74,4 @@ suite "Generated from signatures": check sigResults[1] == "0x47173285A8D7341E5E972FC677286384F802F8EF42A5EC5F03BBFA254CB01FAD" server.stop() -server.close() +waitFor server.closeWait() diff --git a/tests/testhttp.nim b/tests/testhttp.nim index 3ea9dd8..ab912cb 100644 --- a/tests/testhttp.nim +++ b/tests/testhttp.nim @@ -177,4 +177,4 @@ suite "HTTP Server/HTTP Client RPC test suite": check waitFor(disconTest("localhost", Port(8545), 7, 200)) == true httpsrv.stop() -httpsrv.close() +waitFor httpsrv.closeWait() diff --git a/tests/testrpcmacro.nim b/tests/testrpcmacro.nim index dd8687c..b052bd0 100644 --- a/tests/testrpcmacro.nim +++ b/tests/testrpcmacro.nim @@ -157,4 +157,4 @@ suite "Server types": check r == %"hello world" s.stop() -s.close() +waitFor s.closeWait() diff --git a/tests/testserverclient.nim b/tests/testserverclient.nim index d8f8e58..381a71a 100644 --- a/tests/testserverclient.nim +++ b/tests/testserverclient.nim @@ -18,4 +18,4 @@ suite "Server/Client RPC": check r.result.getStr == "Hello abc data: [1, 2, 3, 4]" srv.stop() -srv.close() +waitFor srv.closeWait()