I'm trying to make a test for std/net, which starts a server, starts a client, makes sure they connect and know each other's identities, that's about it.
I don't know much about testament, so i'm looking for an example of a multi-process test, but I've only seen async server tests, or ones that connect to a website or something, is there a way to do this without async?
ok, so i've got this:
discard """
action: "compile"
joinable: false
batchable: false
cmd: "bash -c \"nim $target -r --hints:off -d:ssl pskserv.nim & nim $target -r --hints:off -d:ssl -r pskclient.nim\""
nimout:'''
accepted connection
identity hint \"hello\"
got connection with identity foo'''
"""
which runs everything just fine, outputs the right stuff to stdout, exitcode 0, but the test fails with reNimcCrash
what can i do to make this pass?
got a better one, but i still don't know how to do it for all the backends:
discard """
action: "run"
joinable: false
batchable: false
"""
import osproc
var ps:seq[Process]
for prog in ["pskserv.nim","pskclient.nim"]:
ps.add startProcess("nim",args=["c","-r","--hints:off","-d:ssl",prog],options={poUsePath,poDaemon,poStdErrToStdOut})
var (lines,exC) = ps[0].readLines
assert exC == 0
assert lines == @["accepted connection","got connection with identity foo"]
(lines,exC) = ps[1].readLines
assert exC == 0
assert lines == @["""identity hint "hello""""]
for p in ps:
close(p)
I'm using this to test asyncnet sockets
proc simulateAsyncClientServer*(function: (AsyncSocket, AsyncSocket) -> void) =
let ssocket = newAsyncSocket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
let rclient = newAsyncSocket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
var sclient: AsyncSocket
defer:
ssocket.close()
rclient.close()
sclient.close()
let port = 55145.Port
let host = "127.0.0.1"
ssocket.setSockOpt(OptReuseAddr, true)
ssocket.bindAddr(port, host)
ssocket.listen()
waitfor rclient.connect(host, port)
sclient = waitfor ssocket.accept()
function(sclient, rclient)