From a9c7794e8944b67ab58e6445b6801966d5610918 Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Fri, 12 Jul 2024 08:10:33 -0700 Subject: [PATCH] test(supply-chain-app-backend): fix via-npm-script.test.ts hanging 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 --- .github/workflows/ci.yaml | 2 ++ .../src/main/typescript/public-api.ts | 1 + .../src/main/typescript/supply-chain-app.ts | 9 ++++++++- .../integration/supply-chain-cli-via-npm-script.test.ts | 3 ++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9aeb172065..b8c7c68a09 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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: diff --git a/examples/cactus-example-supply-chain-backend/src/main/typescript/public-api.ts b/examples/cactus-example-supply-chain-backend/src/main/typescript/public-api.ts index 13e91cce55..7f597658d2 100755 --- a/examples/cactus-example-supply-chain-backend/src/main/typescript/public-api.ts +++ b/examples/cactus-example-supply-chain-backend/src/main/typescript/public-api.ts @@ -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"; diff --git a/examples/cactus-example-supply-chain-backend/src/main/typescript/supply-chain-app.ts b/examples/cactus-example-supply-chain-backend/src/main/typescript/supply-chain-app.ts index ba86e92652..c043f224e7 100644 --- a/examples/cactus-example-supply-chain-backend/src/main/typescript/supply-chain-app.ts +++ b/examples/cactus-example-supply-chain-backend/src/main/typescript/supply-chain-app.ts @@ -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; @@ -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); diff --git a/examples/cactus-example-supply-chain-backend/src/test/typescript/integration/supply-chain-cli-via-npm-script.test.ts b/examples/cactus-example-supply-chain-backend/src/test/typescript/integration/supply-chain-cli-via-npm-script.test.ts index ccbff0f52a..04749e34bb 100644 --- a/examples/cactus-example-supply-chain-backend/src/test/typescript/integration/supply-chain-cli-via-npm-script.test.ts +++ b/examples/cactus-example-supply-chain-backend/src/test/typescript/integration/supply-chain-cli-via-npm-script.test.ts @@ -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"; @@ -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");