Skip to content

Commit

Permalink
test(supply-chain-app-backend): fix via-npm-script.test.ts hanging
Browse files Browse the repository at this point in the history
1. The test case was hanging at the end because it was waiting  for a
magic string to appear in the logs to indicate that the booting has finished.
2. The problems began when we changed the supply chain app's log message
from mentioning Cactus to Cacti which then invalidated the condition forever.
3. This left it hanging indefinitely and the test case was broken.
4. Now to fix the problem and avoid this happening again in the future
the supply chain app exports the log message pattern as a variable and the
test case imports that directly so if we change the log message in the
future it will automatically make sure that the test is also waiting for
the updated log message pattern to show up in the logs making this class
of bugs impossible to happen.

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Jul 12, 2024
1 parent 5d7ec29 commit e7a53ac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { SUPPLY_CHAIN_APP_OK_LOG_MSG_PATTERN } from "./supply-chain-app";
export { SupplyChainApp } from "./supply-chain-app";
export { ISupplyChainAppOptions } from "./supply-chain-app";
export { launchApp } from "./supply-chain-app-cli";
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ import {
import { SupplyChainCactusPlugin } from "@hyperledger/cactus-example-supply-chain-business-logic-plugin";
import { DiscoveryOptions } from "fabric-network";

/**
* The log pattern message that will be printed on stdout when the
* Supply Chain Application finished booting (it can take a long time).
*/
export const SUPPLY_CHAIN_APP_OK_LOG_MSG_PATTERN =
"Cacti API Server - REST API reachable at:";

export interface ISupplyChainAppOptions {
disableSignalHandlers?: true;
logLevel?: LogLevelDesc;
Expand Down Expand Up @@ -633,7 +640,7 @@ export class SupplyChainApp {
await apiServer.start();

const restApiUrl = `http://127.0.0.1:${properties.apiPort}`;
this.log.info("Cacti API Server - REST API reachable at: %s", restApiUrl);
this.log.info("%s: %s", SUPPLY_CHAIN_APP_OK_LOG_MSG_PATTERN, restApiUrl);

const guiUrl = `http://127.0.0.1:${properties.cockpitPort}`;
this.log.info("SupplyChainApp Web GUI - reachable at: %s", guiUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import test, { Test } from "tape-promise/tape";
import { LogLevelDesc } from "@hyperledger/cactus-common";
import { pruneDockerAllIfGithubAction } from "@hyperledger/cactus-test-tooling";
import * as publicApi from "../../../main/typescript/public-api";
import { SUPPLY_CHAIN_APP_OK_LOG_MSG_PATTERN } from "../../../main/typescript/public-api";

const testCase = "SupplyChainApp can launch via root package.json script";
const logLevel: LogLevelDesc = "TRACE";
Expand Down Expand Up @@ -91,7 +92,7 @@ test(testCase, async (t: Test) => {
const logs = [];
for await (const data of child.stdout) {
console.log(`[child]: ${data}`);
if (data.includes("Cactus API reachable http")) {
if (data.includes(SUPPLY_CHAIN_APP_OK_LOG_MSG_PATTERN)) {
console.log("Sending kill signal to child process...");
apiIsHealthy = true;
const killedOK = child.kill("SIGKILL");
Expand Down

0 comments on commit e7a53ac

Please sign in to comment.