mirror of
https://github.com/status-im/nim-codex.git
synced 2025-02-08 08:53:45 +00:00
- need to test with longer tests to ensure the parallelisation is truly happening - is the +10 hardhat port needed? - try with more integration tests # Conflicts: # tests/integration/hardhatprocess.nim # tests/integration/multinodes.nim # tests/integration/testcli.nim # tests/testIntegration.nim
25 lines
887 B
Nim
25 lines
887 B
Nim
import pkg/chronos
|
|
import pkg/codex/logutils
|
|
|
|
proc nextFreePort*(startPort: int): Future[int] {.async: (raises:[CancelledError]).} =
|
|
|
|
proc client(server: StreamServer, transp: StreamTransport) {.async.} =
|
|
await transp.closeWait()
|
|
|
|
var port = startPort
|
|
while true:
|
|
trace "checking if port is free", port
|
|
try:
|
|
let host = initTAddress("127.0.0.1", port)
|
|
# We use ReuseAddr here only to be able to reuse the same IP/Port when
|
|
# there's a TIME_WAIT socket. It's useful when running the test multiple
|
|
# times or if a test ran previously using the same port.
|
|
var server = createStreamServer(host, client, {ReuseAddr})
|
|
trace "port is free", port
|
|
await server.closeWait()
|
|
return port
|
|
except TransportOsError:
|
|
trace "port is not free", port
|
|
inc port
|
|
except TransportAddressError:
|
|
raiseAssert "bad address" |