Segregate logs files in single directory

This commit is contained in:
Franck Royer 2021-03-15 13:38:36 +11:00
parent 548c50668a
commit a6cbdf3117
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
3 changed files with 38 additions and 23 deletions

View File

@ -0,0 +1,22 @@
import fs, { promises as asyncFs } from 'fs';
import { promisify } from 'util';
import { delay } from './delay';
export const existsAsync = (filepath: string) =>
asyncFs.access(filepath, fs.constants.F_OK);
export const openAsync = promisify(fs.open);
export const mkdirAsync = asyncFs.mkdir;
export async function waitForFile(path: string) {
let found = false;
do {
try {
await existsAsync(path);
found = true;
} catch (e) {
await delay(500);
}
} while (!found);
}

View File

@ -1,24 +1,7 @@
import fs, { promises as asyncFs } from 'fs';
import pTimeout from 'p-timeout'; import pTimeout from 'p-timeout';
import { Tail } from 'tail'; import { Tail } from 'tail';
import { delay } from './delay'; import { waitForFile } from './async_fs';
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) { export default async function waitForLine(filepath: string, logLine: string) {
await pTimeout(waitForFile(filepath), 2000); await pTimeout(waitForFile(filepath), 2000);

View File

@ -1,7 +1,5 @@
import { ChildProcess, spawn } from 'child_process'; import { ChildProcess, spawn } from 'child_process';
import { randomInt } from 'crypto'; import { randomInt } from 'crypto';
import * as fs from 'fs';
import { promisify } from 'util';
import axios from 'axios'; import axios from 'axios';
import Multiaddr from 'multiaddr'; import Multiaddr from 'multiaddr';
@ -11,14 +9,15 @@ import PeerId from 'peer-id';
import { Message } from '../lib/waku_message'; import { Message } from '../lib/waku_message';
import { TOPIC } from '../lib/waku_relay'; import { TOPIC } from '../lib/waku_relay';
import { existsAsync, mkdirAsync, openAsync } from './async_fs';
import waitForLine from './log_file'; import waitForLine from './log_file';
const openAsync = promisify(fs.open);
const NIM_WAKU_DEFAULT_P2P_PORT = 60000; const NIM_WAKU_DEFAULT_P2P_PORT = 60000;
const NIM_WAKU_DEFAULT_RPC_PORT = 8545; const NIM_WAKU_DEFAULT_RPC_PORT = 8545;
const NIM_WAKU_BIN = '/home/froyer/src/status-im/nim-waku/build/wakunode2'; const NIM_WAKU_BIN = '/home/froyer/src/status-im/nim-waku/build/wakunode2';
const LOG_DIR = './log';
export interface Args { export interface Args {
staticnode?: string; staticnode?: string;
nat?: 'none'; nat?: 'none';
@ -41,10 +40,21 @@ export class NimWaku {
const logFilePrefix = testName.replace(/ /g, '_').replace(/[':()]/g, ''); const logFilePrefix = testName.replace(/ /g, '_').replace(/[':()]/g, '');
this.logPath = `./${logFilePrefix}-nim-waku.log`; this.logPath = `${LOG_DIR}/${logFilePrefix}-nim-waku.log`;
} }
async start(args: Args) { async start(args: Args) {
try {
await existsAsync(LOG_DIR);
} catch (e) {
try {
await mkdirAsync(LOG_DIR);
} catch (e) {
// Looks like 2 tests tried to create the director at the same time,
// it can be ignored
}
}
const logFile = await openAsync(this.logPath, 'w'); const logFile = await openAsync(this.logPath, 'w');
const mergedArgs = defaultArgs(); const mergedArgs = defaultArgs();