Skip to content

Commit

Permalink
fix(test): prune docker resources when in GitHub Action
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Mar 22, 2021
1 parent b89dfa7 commit d40a67d
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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();

Expand Down Expand Up @@ -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();
});
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -17,14 +20,19 @@ import {
JvmTypeKind,
} from "../../../main/typescript/generated/openapi/typescript-axios/index";

const testCase = "Invocation of uploaded cordapps to nodes via SSH+SCP works";
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: "hyperledger/cactus-corda-4-6-all-in-one-obligation",
imageVersion: "2021-03-19-feat-686",
// imageName: "caio",
// imageVersion: "latest",
logLevel,
});
t.ok(ledger, "CordaTestLedger instantaited OK");
Expand Down Expand Up @@ -311,3 +319,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();
});
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -17,9 +20,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: "hyperledger/cactus-corda-4-6-all-in-one-obligation",
imageVersion: "2021-03-04-ac0d32a",
Expand Down Expand Up @@ -429,3 +439,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();
});
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -31,9 +34,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,
Expand Down Expand Up @@ -203,3 +213,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();
});
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -36,9 +39,16 @@ import { DiscoveryOptions } from "fabric-network";
* ```
*/

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,
Expand Down Expand Up @@ -193,3 +203,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();
});
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -39,17 +39,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({
Expand Down Expand Up @@ -209,3 +208,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();
});
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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();

Expand Down Expand Up @@ -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();
});
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -21,17 +21,27 @@ 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 {
IPluginConsortiumManualOptions,
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,
Expand Down Expand Up @@ -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();
});
Loading

0 comments on commit d40a67d

Please sign in to comment.