From c99e02af206ec968546c564315b28732ecb5f939 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Mon, 15 Mar 2021 13:25:14 +1100 Subject: [PATCH] Allow waiting for nim waku logs from test --- src/lib/node.spec.ts | 8 ++++---- src/test_utils/nim_waku.ts | 17 +++++++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/lib/node.spec.ts b/src/lib/node.spec.ts index 5256cf1742..346e47bbe1 100644 --- a/src/lib/node.spec.ts +++ b/src/lib/node.spec.ts @@ -59,8 +59,8 @@ test('Nim-interop: nim-waku node connects to js node', async (t) => { ); const multiAddrWithId = localMultiaddr + '/p2p/' + peerId; - const nimWaku = new NimWaku(); - await nimWaku.start(t.title, { staticnode: multiAddrWithId }); + const nimWaku = new NimWaku(t.title); + await nimWaku.start({ staticnode: multiAddrWithId }); const nimPeers = await nimWaku.peers(); @@ -88,8 +88,8 @@ test('Nim-interop: js node receives default subscription from nim node', async ( ); const multiAddrWithId = localMultiaddr + '/p2p/' + peerId; - const nimWaku = new NimWaku(); - await nimWaku.start(t.title, { staticnode: multiAddrWithId }); + const nimWaku = new NimWaku(t.title); + await nimWaku.start({ staticnode: multiAddrWithId }); const nimPeerId = await nimWaku.getPeerId(); const subscribers = node.pubsub.getSubscribers(TOPIC); diff --git a/src/test_utils/nim_waku.ts b/src/test_utils/nim_waku.ts index b2a7860dd4..0e43c38c31 100644 --- a/src/test_utils/nim_waku.ts +++ b/src/test_utils/nim_waku.ts @@ -34,17 +34,18 @@ export class NimWaku { private process?: ChildProcess; private portsShift: number; private peerId?: PeerId; + private logPath: string; - constructor() { + constructor(testName: string) { this.portsShift = randomInt(0, 5000); - } - async start(testName: string, args: Args) { const logFilePrefix = testName.replace(/ /g, '_').replace(/[':()]/g, ''); - const logPath = `./${logFilePrefix}-nim-waku.log`; + this.logPath = `./${logFilePrefix}-nim-waku.log`; + } - const logFile = await openAsync(logPath, 'w'); + async start(args: Args) { + const logFile = await openAsync(this.logPath, 'w'); const mergedArgs = defaultArgs(); @@ -65,7 +66,11 @@ export class NimWaku { console.log(`ERROR: nim-waku node stopped: ${signal}`); }); - await waitForLine(logPath, 'RPC Server started'); + await this.waitForLog('RPC Server started'); + } + + async waitForLog(msg: string) { + return waitForLine(this.logPath, msg); } /** Calls nim-waku2 JSON-RPC API `get_waku_v2_admin_v1_peers` to check