From 61e3f76ed910c9b04b36f995456213018cc0e7ba Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Sat, 20 Mar 2021 14:28:30 -0700 Subject: [PATCH] fix(ci): disk full issues on GitHub Action Workflow runner #698 Updates the test cases that use ledger containers to clean up after themselves not just by stopping and deleting the containers but by also doing a docker prune of the containers, images, networks and volumes as well. What we hope to accomplish here is that the GHA CI will stop failing with disk full errors. Fixes #698 Signed-off-by: Peter Somogyvari --- .../deploy-contract-from-json.test.ts | 25 +++++++++++++--- .../jvm-kotlin-spring-server.test.ts | 20 +++++++++++-- .../deploy-cc-from-golang-source.test.ts | 22 ++++++++++++-- .../run-transaction-endpoint-v1.test.ts | 24 ++++++++++++--- .../run-transaction-endpoint-v1.test.ts | 29 +++++++++++-------- .../deploy-contract-from-json.test.ts | 18 ++++++++++-- .../api-client-routing-node-to-node.test.ts | 24 ++++++++++++--- .../sign-transaction-endpoint.test.ts | 25 +++++++++++++--- .../deploy-contract-via-web-service.test.ts | 28 +++++++++++++++--- 9 files changed, 176 insertions(+), 39 deletions(-) diff --git a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts index f8c0919fdb..6816502955 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts @@ -1,4 +1,4 @@ -import test, { Test } from "tape"; +import test, { Test } from "tape-promise/tape"; import { v4 as uuidv4 } from "uuid"; import { PluginRegistry } from "@hyperledger/cactus-core"; import { @@ -9,14 +9,25 @@ import { Web3SigningCredentialCactusKeychainRef, } from "../../../../../main/typescript/public-api"; import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; -import { BesuTestLedger } from "@hyperledger/cactus-test-tooling"; +import { + BesuTestLedger, + pruneDockerAllIfGithubAction, +} from "@hyperledger/cactus-test-tooling"; import { LogLevelDesc } from "@hyperledger/cactus-common"; import HelloWorldContractJson from "../../../../solidity/hello-world-contract/HelloWorld.json"; import Web3 from "web3"; import { PluginImportType } from "@hyperledger/cactus-core-api"; -test("deploys contract via .json file", async (t: Test) => { - const logLevel: LogLevelDesc = "TRACE"; +const testCase = "deploys contract via .json file"; +const logLevel: LogLevelDesc = "TRACE"; + +test("BEFORE " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +}); + +test(testCase, async (t: Test) => { const besuTestLedger = new BesuTestLedger(); await besuTestLedger.start(); @@ -359,3 +370,9 @@ test("deploys contract via .json file", async (t: Test) => { t.end(); }); + +test("AFTER " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +}); diff --git a/packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/jvm-kotlin-spring-server.test.ts b/packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/jvm-kotlin-spring-server.test.ts index ae2cc424d8..c79f2d45f5 100644 --- a/packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/jvm-kotlin-spring-server.test.ts +++ b/packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/jvm-kotlin-spring-server.test.ts @@ -1,7 +1,10 @@ import test, { Test } from "tape-promise/tape"; import { v4 as internalIpV4 } from "internal-ip"; -import { CordaTestLedger } from "@hyperledger/cactus-test-tooling"; +import { + CordaTestLedger, + pruneDockerAllIfGithubAction, +} from "@hyperledger/cactus-test-tooling"; import { LogLevelDesc } from "@hyperledger/cactus-common"; import { SampleCordappEnum, @@ -15,9 +18,16 @@ import { JvmTypeKind, } from "../../../main/typescript/generated/openapi/typescript-axios/index"; +const testCase = "Tests are passing on the JVM side"; const logLevel: LogLevelDesc = "TRACE"; -test("Tests are passing on the JVM side", async (t: Test) => { +test("BEFORE " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +}); + +test(testCase, async (t: Test) => { const ledger = new CordaTestLedger({ imageName: "petermetz/cactus-corda-4-6-all-in-one-obligation", imageVersion: "2021-03-04-ac0d32a", @@ -414,3 +424,9 @@ test("Tests are passing on the JVM side", async (t: Test) => { t.end(); }); + +test("AFTER " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +}); diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/deploy-contract-go-bin-endpoint-v1/deploy-contract/deploy-cc-from-golang-source.test.ts b/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/deploy-contract-go-bin-endpoint-v1/deploy-contract/deploy-cc-from-golang-source.test.ts index 7f1923420d..b2b9129483 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/deploy-contract-go-bin-endpoint-v1/deploy-contract/deploy-cc-from-golang-source.test.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/deploy-contract-go-bin-endpoint-v1/deploy-contract/deploy-cc-from-golang-source.test.ts @@ -1,13 +1,16 @@ import { AddressInfo } from "net"; import http from "http"; -import test, { Test } from "tape"; +import test, { Test } from "tape-promise/tape"; import { v4 as uuidv4 } from "uuid"; import express from "express"; import bodyParser from "body-parser"; -import { FabricTestLedgerV1 } from "@hyperledger/cactus-test-tooling"; +import { + FabricTestLedgerV1, + pruneDockerAllIfGithubAction, +} from "@hyperledger/cactus-test-tooling"; import { IListenOptions, @@ -34,9 +37,16 @@ import { IPluginLedgerConnectorFabricOptions } from "../../../../../main/typescr import { DiscoveryOptions } from "fabric-network"; import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; +const testCase = "deploys contract from go source"; const logLevel: LogLevelDesc = "TRACE"; -test("deploys contract from go source", async (t: Test) => { +test("BEFORE " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +}); + +test(testCase, async (t: Test) => { const ledger = new FabricTestLedgerV1({ emitContainerLogs: true, publishAllPorts: true, @@ -208,3 +218,9 @@ test("deploys contract from go source", async (t: Test) => { t.equal(getRes.data.functionOutput, testValue, "get returns UUID OK"); t.end(); }); + +test("AFTER " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +}); diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v1-4-x/run-transaction-endpoint-v1.test.ts b/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v1-4-x/run-transaction-endpoint-v1.test.ts index 0fbab326c1..77f1068b26 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v1-4-x/run-transaction-endpoint-v1.test.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v1-4-x/run-transaction-endpoint-v1.test.ts @@ -1,13 +1,16 @@ import http from "http"; import { AddressInfo } from "net"; -import test, { Test } from "tape"; +import test, { Test } from "tape-promise/tape"; import { v4 as uuidv4 } from "uuid"; import bodyParser from "body-parser"; import express from "express"; -import { FabricTestLedgerV1 } from "@hyperledger/cactus-test-tooling"; +import { + FabricTestLedgerV1, + pruneDockerAllIfGithubAction, +} from "@hyperledger/cactus-test-tooling"; import { PluginRegistry } from "@hyperledger/cactus-core"; import { @@ -38,9 +41,16 @@ import { K_CACTUS_FABRIC_TOTAL_TX_COUNT } from "../../../../main/typescript/prom * ``` */ -test("runs tx on a Fabric v1.4.8 ledger", async (t: Test) => { - const logLevel: LogLevelDesc = "TRACE"; +const testCase = "runs tx on a Fabric v1.4.8 ledger"; +const logLevel: LogLevelDesc = "TRACE"; + +test("BEFORE " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +}); +test(testCase, async (t: Test) => { const ledger = new FabricTestLedgerV1({ publishAllPorts: true, emitContainerLogs: false, @@ -203,3 +213,9 @@ test("runs tx on a Fabric v1.4.8 ledger", async (t: Test) => { } t.end(); }); + +test("AFTER " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +}); diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v2-2-x/run-transaction-endpoint-v1.test.ts b/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v2-2-x/run-transaction-endpoint-v1.test.ts index 526290bdd6..daa4c77774 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v2-2-x/run-transaction-endpoint-v1.test.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v2-2-x/run-transaction-endpoint-v1.test.ts @@ -1,15 +1,15 @@ import http from "http"; import { AddressInfo } from "net"; -import test, { Test } from "tape"; +import test, { Test } from "tape-promise/tape"; import { v4 as uuidv4 } from "uuid"; import bodyParser from "body-parser"; import express from "express"; import { - Containers, FabricTestLedgerV1, + pruneDockerAllIfGithubAction, } from "@hyperledger/cactus-test-tooling"; import { PluginRegistry } from "@hyperledger/cactus-core"; @@ -42,17 +42,16 @@ import { DiscoveryOptions } from "fabric-network"; * ``` */ -test("runs tx on a Fabric v2.2.0 ledger", async (t: Test) => { - // Always set to true when GitHub Actions is running the workflow. - // You can use this variable to differentiate when tests are being run locally or by GitHub Actions. - // @see https://docs.github.com/en/actions/reference/environment-variables - if (process.env.GITHUB_ACTIONS === "true") { - // Github Actions started to run out of disk space recently so we have this - // hack here to attempt to free up disk space when running inside a VM of - // the CI system. - await Containers.pruneDockerResources(); - } +const testCase = "runs tx on a Fabric v2.2.0 ledger"; +const logLevel: LogLevelDesc = "TRACE"; + +test("BEFORE " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +}); +test(testCase, async (t: Test) => { const logLevel: LogLevelDesc = "TRACE"; const ledger = new FabricTestLedgerV1({ @@ -220,3 +219,9 @@ test("runs tx on a Fabric v2.2.0 ledger", async (t: Test) => { } t.end(); }); + +test("AFTER " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +}); diff --git a/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-from-json.test.ts b/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-from-json.test.ts index fbe173ebd9..c37f4b9af9 100644 --- a/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-from-json.test.ts +++ b/packages/cactus-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-from-json.test.ts @@ -1,4 +1,4 @@ -import test, { Test } from "tape"; +import test, { Test } from "tape-promise/tape"; import Web3 from "web3"; import { v4 as uuidV4 } from "uuid"; @@ -19,12 +19,20 @@ import { QuorumTestLedger, IQuorumGenesisOptions, IAccount, + pruneDockerAllIfGithubAction, } from "@hyperledger/cactus-test-tooling"; import { PluginRegistry } from "@hyperledger/cactus-core"; +const testCase = "Quorum Ledger Connector Plugin"; const logLevel: LogLevelDesc = "INFO"; -test("Quorum Ledger Connector Plugin", async (t: Test) => { +test("BEFORE " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +}); + +test(testCase, async (t: Test) => { const ledger = new QuorumTestLedger(); await ledger.start(); @@ -389,3 +397,9 @@ test("Quorum Ledger Connector Plugin", async (t: Test) => { t.end(); }); + +test("AFTER " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +}); diff --git a/packages/cactus-test-api-client/src/test/typescript/integration/api-client-routing-node-to-node.test.ts b/packages/cactus-test-api-client/src/test/typescript/integration/api-client-routing-node-to-node.test.ts index f8b8498a76..6b557009fe 100644 --- a/packages/cactus-test-api-client/src/test/typescript/integration/api-client-routing-node-to-node.test.ts +++ b/packages/cactus-test-api-client/src/test/typescript/integration/api-client-routing-node-to-node.test.ts @@ -1,6 +1,6 @@ import { AddressInfo } from "net"; -import test, { Test } from "tape"; +import test, { Test } from "tape-promise/tape"; import { v4 as uuidV4 } from "uuid"; import { JWK } from "jose"; import Web3 from "web3"; @@ -21,7 +21,10 @@ import { PluginLedgerConnectorQuorum, Web3SigningCredentialType, } from "@hyperledger/cactus-plugin-ledger-connector-quorum"; -import { QuorumTestLedger } from "@hyperledger/cactus-test-tooling"; +import { + pruneDockerAllIfGithubAction, + QuorumTestLedger, +} from "@hyperledger/cactus-test-tooling"; import { LogLevelDesc, Servers } from "@hyperledger/cactus-common"; import { @@ -29,9 +32,16 @@ import { PluginConsortiumManual, } from "@hyperledger/cactus-plugin-consortium-manual"; -test("Routes to correct node based on ledger ID", async (t: Test) => { - const logLevel: LogLevelDesc = "TRACE"; +const logLevel: LogLevelDesc = "TRACE"; +const testCase = "Routes to correct node based on ledger ID"; + +test("BEFORE " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +}); +test(testCase, async (t: Test) => { const ledger1: Ledger = { id: "my_cool_ledger_that_i_want_to_transact_on", ledgerType: LedgerType.QUORUM2X, @@ -276,3 +286,9 @@ test("Routes to correct node based on ledger ID", async (t: Test) => { t.end(); }); + +test("AFTER " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +}); diff --git a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/sign-transaction-endpoint.test.ts b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/sign-transaction-endpoint.test.ts index f04ce9900c..9916b7cbb8 100644 --- a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/sign-transaction-endpoint.test.ts +++ b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/sign-transaction-endpoint.test.ts @@ -1,4 +1,4 @@ -import test, { Test } from "tape"; +import test, { Test } from "tape-promise/tape"; import { v4 as uuidv4 } from "uuid"; import { createServer } from "http"; @@ -16,7 +16,10 @@ import { LogLevelDesc, } from "@hyperledger/cactus-common"; -import { BesuTestLedger } from "@hyperledger/cactus-test-tooling"; +import { + BesuTestLedger, + pruneDockerAllIfGithubAction, +} from "@hyperledger/cactus-test-tooling"; import { Configuration, @@ -30,8 +33,16 @@ import { PluginRegistry } from "@hyperledger/cactus-core"; import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; -test("Test sign transaction endpoint", async (t: Test) => { - const logLevel: LogLevelDesc = "TRACE"; +const testCase = "Test sign transaction endpoint"; +const logLevel: LogLevelDesc = "TRACE"; + +test("BEFORE " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +}); + +test(testCase, async (t: Test) => { const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); const keychainId = uuidv4(); const keychainRef = uuidv4(); @@ -174,3 +185,9 @@ test("Test sign transaction endpoint", async (t: Test) => { ); } }); + +test("AFTER " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +}); diff --git a/packages/cactus-test-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-via-web-service.test.ts b/packages/cactus-test-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-via-web-service.test.ts index 23060bee23..90db510b6a 100644 --- a/packages/cactus-test-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-via-web-service.test.ts +++ b/packages/cactus-test-plugin-ledger-connector-quorum/src/test/typescript/integration/plugin-ledger-connector-quorum/deploy-contract/deploy-contract-via-web-service.test.ts @@ -1,13 +1,18 @@ -import test, { Test } from "tape"; +import test, { Test } from "tape-promise/tape"; import Web3 from "web3"; import { v4 as uuidV4 } from "uuid"; import { QuorumTestLedger, IQuorumGenesisOptions, IAccount, + pruneDockerAllIfGithubAction, } from "@hyperledger/cactus-test-tooling"; import HelloWorldContractJson from "../../../../solidity/hello-world-contract/HelloWorld.json"; -import { Logger, LoggerProvider } from "@hyperledger/cactus-common"; +import { + Logger, + LoggerProvider, + LogLevelDesc, +} from "@hyperledger/cactus-common"; import { PluginLedgerConnectorQuorum, DefaultApi, @@ -28,12 +33,21 @@ import { ICactusPlugin } from "@hyperledger/cactus-core-api"; import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; import { AddressInfo } from "net"; +const logLevel: LogLevelDesc = "TRACE"; +const testCase = "deploys contract via REST API"; + const log: Logger = LoggerProvider.getOrCreate({ label: "test-deploy-contract-via-web-service", - level: "trace", + level: logLevel, +}); + +test("BEFORE " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); }); -test("deploys contract via REST API", async (t: Test) => { +test(testCase, async (t: Test) => { // 1. Instantiate a ledger object const ledger = new QuorumTestLedger(); @@ -245,3 +259,9 @@ test("deploys contract via REST API", async (t: Test) => { t.end(); }); + +test("AFTER " + testCase, async (t: Test) => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await t.doesNotReject(pruning, "Pruning didnt throw OK"); + t.end(); +});