From 43c0a48245be2b24ffb8373d81d86f5911f285e8 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Thu, 12 May 2022 13:42:18 +0200 Subject: [PATCH] [tests] move node management into separate module And add a debug option that writes the output of the node during integration tests to stdout. --- tests/integration/nodes.nim | 22 ++++++++++++++++++++++ tests/testIntegration.nim | 18 +----------------- 2 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 tests/integration/nodes.nim diff --git a/tests/integration/nodes.nim b/tests/integration/nodes.nim new file mode 100644 index 00000000..7ef2da05 --- /dev/null +++ b/tests/integration/nodes.nim @@ -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() diff --git a/tests/testIntegration.nim b/tests/testIntegration.nim index acfa0c75..9864e22b 100644 --- a/tests/testIntegration.nim +++ b/tests/testIntegration.nim @@ -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"]