Skip to content

Commit fda0488

Browse files
committed
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 <[email protected]>
1 parent 02a8de2 commit fda0488

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/jvm-kotlin-spring-server.test.ts

+2-15
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,8 @@ test(testCase, async (t: Test) => {
3636
t.ok(ledger, "CordaTestLedger instantaited OK");
3737

3838
test.onFinish(async () => {
39-
try {
40-
const logBuffer = ((await ledgerContainer.logs({
41-
follow: false,
42-
stdout: true,
43-
stderr: true,
44-
})) as unknown) as Buffer;
45-
const logs = logBuffer.toString("utf-8");
46-
t.comment(`[CordaAllInOne] ${logs}`);
47-
} finally {
48-
try {
49-
await ledger.stop();
50-
} finally {
51-
await ledger.destroy();
52-
}
53-
}
39+
await ledger.stop();
40+
await ledger.destroy();
5441
});
5542
const ledgerContainer = await ledger.start();
5643
t.ok(ledgerContainer, "CordaTestLedger container truthy post-start() OK");

packages/cactus-test-tooling/src/main/typescript/corda/corda-test-ledger.ts

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
Logger,
1414
LoggerProvider,
1515
Checks,
16+
Bools,
1617
} from "@hyperledger/cactus-common";
1718
import { Base64File } from "../common/base64-file";
1819
import {
@@ -32,6 +33,7 @@ export interface ICordaTestLedgerConstructorOptions {
3233
rpcPortC?: number;
3334
logLevel?: LogLevelDesc;
3435
envVars?: string[];
36+
emitContainerLogs?: boolean;
3537
}
3638

3739
/*
@@ -81,6 +83,7 @@ export class CordaTestLedger implements ITestLedger {
8183
public readonly rpcPortA: number;
8284
public readonly rpcPortB: number;
8385
public readonly rpcPortC: number;
86+
public readonly emitContainerLogs: boolean;
8487

8588
private container: Container | undefined;
8689
private containerId: string | undefined;
@@ -96,6 +99,9 @@ export class CordaTestLedger implements ITestLedger {
9699
this.rpcPortB = opts.rpcPortB || DEFAULTS.rpcPortB;
97100
this.rpcPortC = opts.rpcPortC || DEFAULTS.rpcPortC;
98101
this.rpcPortNotary = opts.rpcPortNotary || DEFAULTS.rpcPortNotary;
102+
this.emitContainerLogs = Bools.isBooleanStrict(opts.emitContainerLogs)
103+
? (opts.emitContainerLogs as boolean)
104+
: true;
99105

100106
this.envVars = opts.envVars ? opts.envVars : DEFAULTS.envVars;
101107
Checks.truthy(Array.isArray(this.envVars), `${fnTag}:envVars not an array`);
@@ -168,6 +174,14 @@ export class CordaTestLedger implements ITestLedger {
168174
eventEmitter.once("start", async (container: Container) => {
169175
this.container = container;
170176
this.containerId = container.id;
177+
if (this.emitContainerLogs) {
178+
const logOptions = { follow: true, stderr: true, stdout: true };
179+
const logStream = await container.logs(logOptions);
180+
logStream.on("data", (data: Buffer) => {
181+
const fnTag = `[${this.getContainerImageName()}]`;
182+
this.log.debug(`${fnTag} %o`, data.toString("utf-8"));
183+
});
184+
}
171185
try {
172186
let isHealthy = false;
173187
do {

0 commit comments

Comments
 (0)