diff --git a/tests/integration/codexprocess.nim b/tests/integration/codexprocess.nim index 1becc909..18a3ea41 100644 --- a/tests/integration/codexprocess.nim +++ b/tests/integration/codexprocess.nim @@ -7,6 +7,7 @@ import pkg/ethers import pkg/libp2p import std/os import std/strutils +import std/times import codex/conf import ./codexclient import ./nodeprocess @@ -78,6 +79,9 @@ proc apiUrl*(node: CodexProcess): string {.raises: [CodexProcessError].} = let config = node.config return "http://" & config.apiBindAddress & ":" & $config.apiPort & "/api/codex/v1" +proc logFile*(node: CodexProcess): ?string {.raises: [CodexProcessError].} = + node.config.logFile + proc client*(node: CodexProcess): CodexClient {.raises: [CodexProcessError].} = if client =? node.client: return client @@ -85,6 +89,25 @@ proc client*(node: CodexProcess): CodexClient {.raises: [CodexProcessError].} = node.client = some client return client +proc updateLogFile(node: CodexProcess, newLogFile: string) = + for arg in node.arguments.mitems: + if arg.startsWith("--log-file="): + arg = "--log-file=" & newLogFile + break + +method restart*(node: CodexProcess) {.async.} = + trace "restarting codex" + await node.stop() + if logFile =? node.logFile: + # chronicles truncates the existing log file on start, so changed the log + # file cli param to create a new one + node.updateLogFile( + logFile & "_restartedAt_" & now().format("yyyy-MM-dd'_'HH-mm-ss") & ".log" + ) + await node.start() + await node.waitUntilStarted() + trace "codex process restarted" + method stop*(node: CodexProcess) {.async: (raises: []).} = logScope: nodeName = node.name diff --git a/tests/integration/nodeprocess.nim b/tests/integration/nodeprocess.nim index e0a7413f..8c86df3b 100644 --- a/tests/integration/nodeprocess.nim +++ b/tests/integration/nodeprocess.nim @@ -137,13 +137,10 @@ method stop*( error = e.msg writeStackTrace() finally: - proc closeProcessStreams() {.async: (raises: []).} = - trace "closing node process' streams" - await node.process.closeWait() - node.process = nil - trace "node process' streams closed" - - asyncSpawn closeProcessStreams() + trace "closing node process' streams" + await node.process.closeWait() + node.process = nil + trace "node process' streams closed" proc waitUntilOutput*( node: NodeProcess, output: string @@ -184,7 +181,7 @@ proc waitUntilStarted*( raise newException(NodeProcessError, "node did not output '" & node.startedOutput & "'") -proc restart*(node: NodeProcess) {.async.} = +method restart*(node: NodeProcess) {.base, async.} = await node.stop() await node.start() await node.waitUntilStarted()