Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(test-tooling): add corda AIO emitContainerLogs option #688

Merged
merged 2 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -90,7 +77,7 @@ test(testCase, async (t: Test) => {
imageVersion: "2021-03-10-feat-623",
envVars: [envVarSpringAppJson],
});
t.ok(CordaConnectorContainer, "CordaConnectorContainer instantaited OK");
t.ok(CordaConnectorContainer, "CordaConnectorContainer instantiated OK");

test.onFinish(async () => {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Logger,
LoggerProvider,
Checks,
Bools,
} from "@hyperledger/cactus-common";
import { Base64File } from "../common/base64-file";
import {
Expand All @@ -32,6 +33,7 @@ export interface ICordaTestLedgerConstructorOptions {
rpcPortC?: number;
logLevel?: LogLevelDesc;
envVars?: string[];
emitContainerLogs?: boolean;
}

/*
Expand Down Expand Up @@ -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;
Expand All @@ -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`);
Expand Down Expand Up @@ -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 {
Expand Down