Allow waiting for nim waku logs from test

This commit is contained in:
Franck Royer 2021-03-15 13:25:14 +11:00
parent b7ce121955
commit c99e02af20
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 15 additions and 10 deletions

View File

@ -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);

View File

@ -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