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.
5. Also sneaking in a hot-fix for a missing test coverage environment
variable for the test package of the manual consortium plugin which was
uncovered by this pull request's execution by chance.

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Jul 15, 2024
1 parent 24b5888 commit b065cbc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2280,6 +2280,8 @@ jobs:
JEST_TEST_RUNNER_DISABLED: false
TAPE_TEST_PATTERN: ./packages/cactus-test-plugin-consortium-manual/src/test/typescript/integration/plugin-consortium-manual/openapi/openapi-validation.test.ts
TAPE_TEST_RUNNER_DISABLED: false
JEST_TEST_COVERAGE_PATH: ./code-coverage-ts/cpt-consortium-manual
JEST_TEST_CODE_COVERAGE_ENABLED: true
needs: build-dev
runs-on: ubuntu-22.04
steps:
Expand Down
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 b065cbc

Please sign in to comment.