[tests] move node management into separate module

And add a debug option that writes the output of
the node during integration tests to stdout.
This commit is contained in:
Mark Spanbroek 2022-05-12 13:42:18 +02:00 committed by markspanbroek
parent 7f9fa0a183
commit 43c0a48245
2 changed files with 23 additions and 17 deletions

View File

@ -0,0 +1,22 @@
import std/osproc
import std/os
import std/streams
import std/strutils
const workingDir = currentSourcePath() / ".." / ".." / ".."
const executable = "build" / "dagger"
proc startNode*(args: openArray[string], debug = false): Process =
if debug:
result = startProcess(executable, workingDir, args, options={poParentStreams})
sleep(1000)
else:
result = startProcess(executable, workingDir, args)
for line in result.outputStream.lines:
if line.contains("Started dagger node"):
break
proc stop*(node: Process) =
node.terminate()
discard node.waitForExit()
node.close()

View File

@ -1,32 +1,16 @@
import std/osproc
import std/os
import std/streams
import std/strutils
import std/httpclient
import std/json
import pkg/asynctest
import pkg/chronos
import pkg/stew/byteutils
import ./integration/nodes
suite "Integration tests":
let workingDir = currentSourcePath() / ".." / ".."
var node1, node2: Process
var baseurl1, baseurl2: string
var client: HttpClient
proc startNode(args: openArray[string]): Process =
result = startProcess("build" / "dagger", workingDir, args)
for line in result.outputStream.lines:
if line.contains("Started dagger node"):
break
proc stop(node: Process) =
node.terminate()
discard node.waitForExit()
node.close()
setup:
node1 = startNode ["--api-port=8080", "--udp-port=8090"]
node2 = startNode ["--api-port=8081", "--udp-port=8091"]