test: Nim-waku connects to JS (success)

This commit is contained in:
Franck Royer 2021-03-11 11:11:37 +11:00
parent a6c1fae5a6
commit 057f5f80ab
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
4 changed files with 99 additions and 11 deletions

43
package-lock.json generated
View File

@ -917,6 +917,12 @@
"resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz",
"integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA=="
},
"@types/tail": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@types/tail/-/tail-2.0.0.tgz",
"integrity": "sha512-TYTfnILhrZUAZKGNgot5+sBDap7oPIzV3818p7g4VhKGc81+/eoEZ93wKBTGnSg/tpDjzWSb8Wx5E737FCH/Sw==",
"dev": true
},
"@typescript-eslint/eslint-plugin": {
"version": "4.16.1",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.16.1.tgz",
@ -9900,6 +9906,17 @@
"dev": true,
"requires": {
"p-timeout": "^3.1.0"
},
"dependencies": {
"p-timeout": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz",
"integrity": "sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==",
"dev": true,
"requires": {
"p-finally": "^1.0.0"
}
}
}
},
"p-fifo": {
@ -9994,12 +10011,10 @@
}
},
"p-timeout": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz",
"integrity": "sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==",
"requires": {
"p-finally": "^1.0.0"
}
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-4.1.0.tgz",
"integrity": "sha512-+/wmHtzJuWii1sXn3HCuH/FTwGhrp4tmJTxSKJbfS+vkipci6osxXM5mY0jUiRzWKMTgUT8l7HFbeSwZAynqHw==",
"dev": true
},
"p-try": {
"version": "2.2.0",
@ -10012,6 +10027,16 @@
"integrity": "sha512-wpgERjNkLrBiFmkMEjuZJEWKKDrNfHCKA1OhyN1wg1FrLkULbviEy6py1AyJUgZ72YWFbZ38FIpnqvVqAlDUwA==",
"requires": {
"p-timeout": "^3.0.0"
},
"dependencies": {
"p-timeout": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz",
"integrity": "sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==",
"requires": {
"p-finally": "^1.0.0"
}
}
}
},
"package-hash": {
@ -11919,6 +11944,12 @@
}
}
},
"tail": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/tail/-/tail-2.2.0.tgz",
"integrity": "sha512-QqUMtWlnzArTvGyjVnAE5fAiXEm2Psvk/BlE7vWx2/dIEWMsAhcNPz7iW6WTiSM8h1fjtCkRMsaWBS1j6rpGBg==",
"dev": true
},
"teeny-request": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/teeny-request/-/teeny-request-6.0.1.tgz",

View File

@ -61,6 +61,7 @@
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@types/axios": "^0.14.0",
"@types/node": "^14.14.31",
"@types/tail": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"ava": "^3.15.0",
@ -80,8 +81,10 @@
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"open-cli": "^6.0.1",
"p-timeout": "^4.1.0",
"prettier": "^2.1.1",
"standard-version": "^9.0.0",
"tail": "^2.2.0",
"ts-node": "^9.0.0",
"typedoc": "^0.20.29",
"typescript": "^4.0.2"

View File

@ -0,0 +1,53 @@
import fs, { promises as asyncFs } from 'fs';
import pTimeout from 'p-timeout';
import { Tail } from 'tail';
import { delay } from './delay';
const existsAsync = (filepath: string) =>
asyncFs.access(filepath, fs.constants.F_OK);
async function waitForFile(path: string) {
let found = false;
do {
try {
await existsAsync(path);
found = true;
} catch (e) {
await delay(500);
}
} while (!found);
}
export default async function waitForLine(filepath: string, logLine: string) {
await pTimeout(waitForFile(filepath), 2000);
const options = {
fromBeginning: true,
follow: true,
};
const tail = new Tail(filepath, options);
await pTimeout(
find(tail, logLine),
60000,
`could not to find '${logLine}' in file '${filepath}'`
);
tail.unwatch();
}
async function find(tail: Tail, line: string) {
return new Promise((resolve, reject) => {
tail.on('line', (data: string) => {
if (data.includes(line)) {
resolve(data);
}
});
tail.on('error', (err) => {
reject(err);
});
});
}

View File

@ -7,7 +7,7 @@ import Multiaddr from 'multiaddr';
import multiaddr from 'multiaddr';
import PeerId from 'peer-id';
import { delay } from './delay';
import waitForLine from './log_file';
const openAsync = promisify(fs.open);
@ -35,7 +35,9 @@ export class NimWaku {
// Start a local only node with the right RPC commands
// The fixed nodekey ensures the node has a fixed Peerid: 16Uiu2HAkyzsXzENw5XBDYEQQAeQTCYjBJpMLgBmEXuwbtcrgxBJ4
const logFile = await openAsync('./nim-waku.log', 'w');
const logPath = './nim-waku.log';
const logFile = await openAsync(logPath, 'w');
const mergedArgs = argsToArray(mergeArguments(args));
console.log(mergedArgs);
@ -52,10 +54,9 @@ export class NimWaku {
console.log(`ERROR: nim-waku node stopped: ${signal}`);
});
// TODO: Wait for line "RPC Server started "
await delay(5000);
await waitForLine(logPath, 'RPC Server started');
console.log('Nim waku RPC is started');
console.log(await this.info());
console.log('Nim waku is hopefully started');
}
/** Calls nim-waku2 JSON-RPC API `get_waku_v2_admin_v1_peers` to check