From 13fe67782addaccabec1d24bb2032da2d8ea3f94 Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Thu, 25 Mar 2021 09:51:56 -0700 Subject: [PATCH] feat(test-tooling): add corda AIO emitContainerLogs option This is the same thing that we added to the Fabric AIO image earlier: Setting the flag controls whether the CordaTestLedger class will automatically pipe the container's own logs onto the logger object of the class instance (CordaTestLedger) or not. By default it does pipe the logs but if it gets spammy developers can turn it off via the flag to avoid having to scroll through thousands of lines of logs that may or may not be useful to them. Signed-off-by: Peter Somogyvari --- .../jvm-kotlin-spring-server.test.ts | 17 ++--------------- .../main/typescript/corda/corda-test-ledger.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/jvm-kotlin-spring-server.test.ts b/packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/jvm-kotlin-spring-server.test.ts index 6d66d8c4db..235f91b558 100644 --- a/packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/jvm-kotlin-spring-server.test.ts +++ b/packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/jvm-kotlin-spring-server.test.ts @@ -36,21 +36,8 @@ test(testCase, async (t: Test) => { t.ok(ledger, "CordaTestLedger instantaited OK"); test.onFinish(async () => { - try { - const logBuffer = ((await ledgerContainer.logs({ - follow: false, - stdout: true, - stderr: true, - })) as unknown) as Buffer; - const logs = logBuffer.toString("utf-8"); - t.comment(`[CordaAllInOne] ${logs}`); - } finally { - try { - await ledger.stop(); - } finally { - await ledger.destroy(); - } - } + await ledger.stop(); + await ledger.destroy(); }); const ledgerContainer = await ledger.start(); t.ok(ledgerContainer, "CordaTestLedger container truthy post-start() OK"); diff --git a/packages/cactus-test-tooling/src/main/typescript/corda/corda-test-ledger.ts b/packages/cactus-test-tooling/src/main/typescript/corda/corda-test-ledger.ts index 374f37eb12..ce31edc1dd 100644 --- a/packages/cactus-test-tooling/src/main/typescript/corda/corda-test-ledger.ts +++ b/packages/cactus-test-tooling/src/main/typescript/corda/corda-test-ledger.ts @@ -13,6 +13,7 @@ import { Logger, LoggerProvider, Checks, + Bools, } from "@hyperledger/cactus-common"; import { Base64File } from "../common/base64-file"; import { @@ -32,6 +33,7 @@ export interface ICordaTestLedgerConstructorOptions { rpcPortC?: number; logLevel?: LogLevelDesc; envVars?: string[]; + emitContainerLogs?: boolean; } /* @@ -81,6 +83,7 @@ export class CordaTestLedger implements ITestLedger { public readonly rpcPortA: number; public readonly rpcPortB: number; public readonly rpcPortC: number; + public readonly emitContainerLogs: boolean; private container: Container | undefined; private containerId: string | undefined; @@ -96,6 +99,9 @@ export class CordaTestLedger implements ITestLedger { this.rpcPortB = opts.rpcPortB || DEFAULTS.rpcPortB; this.rpcPortC = opts.rpcPortC || DEFAULTS.rpcPortC; this.rpcPortNotary = opts.rpcPortNotary || DEFAULTS.rpcPortNotary; + this.emitContainerLogs = Bools.isBooleanStrict(opts.emitContainerLogs) + ? (opts.emitContainerLogs as boolean) + : true; this.envVars = opts.envVars ? opts.envVars : DEFAULTS.envVars; Checks.truthy(Array.isArray(this.envVars), `${fnTag}:envVars not an array`); @@ -168,6 +174,14 @@ export class CordaTestLedger implements ITestLedger { eventEmitter.once("start", async (container: Container) => { this.container = container; this.containerId = container.id; + if (this.emitContainerLogs) { + const logOptions = { follow: true, stderr: true, stdout: true }; + const logStream = await container.logs(logOptions); + logStream.on("data", (data: Buffer) => { + const fnTag = `[${this.getContainerImageName()}]`; + this.log.debug(`${fnTag} %o`, data.toString("utf-8")); + }); + } try { let isHealthy = false; do {