Skip to content

Commit

Permalink
feat(cactus-plugin-ledger-connector-ethereum): add stress test
Browse files Browse the repository at this point in the history
- Return JSON error before checking for Error instance in safeStringifyException
    (for cases when custom errror extends `Error` with `toJSON()` method)
- Move artillery dependency up to the root (since its common tool depdenecy)
- Add web3js http/ws provider options to connector.
- Make http provider optional (can run on ws web3js provider only)
- Don't register async endpoints when WS provider is not available.
- Return 400 for invalid responses from ethereum ledger (to distinguish from connector errors)
- In docker `geth-all-in-one` allow overwriting of default options when starting the ledger.
- Add artillery stress test scripts
    - Template config and artillery functions file
    - Common environment setup file
    - CLI for running the test environment on a separate machine.
    - Jest test to run quickly stress test on same machine.

Depends on #2631

Signed-off-by: Michal Bajer <michal.bajer@fujitsu.com>
  • Loading branch information
outSH authored and petermetz committed Oct 16, 2023
1 parent 117426c commit 55fa26e
Show file tree
Hide file tree
Showing 23 changed files with 836 additions and 159 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ site/
tools/docker/geth-testnet/data-geth1/

.history/
.manual-geth-artillery-config.yaml
10 changes: 5 additions & 5 deletions packages/cactus-common/src/main/typescript/error-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export class CodedError extends Error {
* @returns Safe string representation of an error.
*/
export function safeStringifyException(error: unknown): string {
if (error instanceof Error) {
return sanitizeHtml(error.stack || error.message);
}

// Axios and possibly other lib errors produce nicer output with toJSON() method.
// Use it if available
if (
Expand All @@ -36,7 +32,11 @@ export function safeStringifyException(error: unknown): string {
"toJSON" in error &&
typeof error.toJSON === "function"
) {
return sanitizeHtml(error.toJSON());
return sanitizeHtml(safeStringify(error.toJSON()));
}

if (error instanceof Error) {
return sanitizeHtml(error.stack || error.message);
}

return sanitizeHtml(safeStringify(error));
Expand Down
26 changes: 26 additions & 0 deletions packages/cactus-plugin-ledger-connector-ethereum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,32 @@ To check that all has been installed correctly and that the pugin has no errors
npx jest cactus-plugin-ledger-connector-ethereum
```
### Stess test
- Use CLI for manual setup of test environment and geneartion of artillery config.
- `artillery` must be installed separately (we do not recommend running it if they are any known open vulnerabilities)
#### Setup
``` sh
# Start the test environment
node ./packages/cactus-plugin-ledger-connector-ethereum/dist/lib/test/typescript/benchmark/cli/run-benchmark-environment.js
# Wait until `> artillery run ./.manual-geth-artillery-config.yaml` is printed

# Review artillery config - change scenarios weights or load configuration, adjust target if running on separate machine etc...
vim ./.manual-geth-artillery-config.yaml # config is created in cwd() when starting the environment

# Run artillery
artillery run ./.manual-geth-artillery-config.yaml
```
#### Files
- `./src/test/typescript/benchmark/setup`
- `geth-benchmark-env.ts` contains helper file for setting up an environment used by both CLI and jest test.
- `geth-benchmark-config.yaml` template artillery configuration. You can modify test load and scenarios there.
- `artillery-helper-functions.js` request handlers used by artillery to correcty process some response codes.
- `./src/test/typescript/benchmark/cli`
- `run-benchmark-environment.ts` CLI for starting test environment and patching template artillery config
### Building/running the container image locally
In the Cactus project root say:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
"scripts": {
"codegen": "run-p 'codegen:*'",
"codegen:openapi": "npm run generate-sdk",
"build:dev:backend:postbuild": "npm run copy-artillery-config",
"copy-artillery-config": "cp -af ./src/test/typescript/benchmark/setup/geth-benchmark-config.yaml ./src/test/typescript/benchmark/setup/artillery-helper-functions.js ./dist/lib/test/typescript/benchmark/setup",
"generate-sdk": "run-p 'generate-sdk:*'",
"generate-sdk:typescript-axios": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g typescript-axios -o ./src/main/typescript/generated/openapi/typescript-axios/ --reserved-words-mappings protected=protected",
"watch": "npm-watch",
Expand Down Expand Up @@ -84,10 +86,13 @@
"@hyperledger/cactus-test-geth-ledger": "2.0.0-alpha.2",
"@hyperledger/cactus-test-tooling": "2.0.0-alpha.2",
"@types/express": "4.17.13",
"@types/js-yaml": "4.0.5",
"@types/minimist": "1.2.2",
"@types/sanitize-html": "2.6.2",
"chalk": "4.1.2",
"socket.io": "4.5.4"
"js-yaml": "4.1.0",
"socket.io": "4.5.4",
"web3-eth-accounts": "4.0.6"
},
"engines": {
"node": ">=10",
Expand Down
Loading

0 comments on commit 55fa26e

Please sign in to comment.