Skip to content

Commit

Permalink
refactor: optimize e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iccicci committed May 22, 2024
1 parent 55be8ed commit 3923bbf
Show file tree
Hide file tree
Showing 30 changed files with 55 additions and 88 deletions.
22 changes: 14 additions & 8 deletions .github/workflows/continuous-integration-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:

- name: 🔨 Build
run: |
yarn install --immutable --inline-builds
yarn install --immutable --inline-builds --mode=skip-build
yarn build
docker build --no-cache .
env:
Expand All @@ -67,18 +67,24 @@ jobs:
OGMIOS_URL: 'ws://ogmios:1340'
POSTGRES_PORT: '5435'

- name: Wait for some epochs
- name: Wait for network init
run: |
yarn workspace @cardano-sdk/e2e wait-for-network
env:
DB_SYNC_CONNECTION_STRING: 'postgresql://postgres:doNoUseThisSecret!@localhost:5435/cexplorer'
yarn workspace @cardano-sdk/e2e wait-for-network-init
- name: 🔬 Test - e2e - wallet
- name: 🔬 Test - e2e - wallet at epoch 0
run: |
yarn workspace @cardano-sdk/e2e test:wallet
yarn workspace @cardano-sdk/e2e test:providers
yarn workspace @cardano-sdk/e2e test:wallet:0
yarn workspace @cardano-sdk/e2e test:projection
- name: Wait for epoch 3
run: |
yarn workspace @cardano-sdk/e2e wait-for-network-epoch-3
- name: 🔬 Test - e2e - wallet at epoch 3
run: |
yarn workspace @cardano-sdk/e2e test:wallet:3
yarn workspace @cardano-sdk/e2e test:pg-boss
yarn workspace @cardano-sdk/e2e test:providers
env:
STAKE_POOL_PROVIDER_URL: 'http://localhost:4000/'

Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ FROM ubuntu-nodejs as nodejs-builder
RUN \
curl --proto '=https' --tlsv1.2 -sSf -L https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - &&\
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list &&\
apt-get update && apt-get install pkg-config libusb-1.0 libudev-dev gcc g++ make gnupg2 yarn -y &&\
yarn global add [email protected]
apt-get update && apt-get install yarn -y
WORKDIR /app
COPY build build
COPY packages/cardano-services/package.json packages/cardano-services/package.json
Expand Down Expand Up @@ -118,10 +117,12 @@ WORKDIR /config
COPY compose/schedules.json .
ENV SCHEDULES=/config/schedules.json
WORKDIR /app/packages/cardano-services
HEALTHCHECK CMD curl -s --fail http://localhost:3003/v1.0.0/health
CMD ["node", "dist/cjs/cli.js", "start-pg-boss-worker"]

FROM cardano-services as projector
WORKDIR /
COPY compose/projector/init.* ./
RUN chmod 755 init.sh
HEALTHCHECK CMD test `curl -fs http://localhost:3000/v1.0.0/health | jq -r ".services[0].projectedTip.blockNo"` -gt 1
CMD ["./init.sh"]
33 changes: 2 additions & 31 deletions compose/common.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.9'

x-from-sdk: &from-sdk
healthcheck:
interval: 10s
Expand Down Expand Up @@ -30,7 +28,7 @@ x-provider-server: &provider-server
target: provider-server
depends_on:
cardano-db-sync:
condition: service_healthy
condition: service_started

x-with-postgres: &with-postgres
depends_on:
Expand Down Expand Up @@ -113,19 +111,12 @@ services:
depends_on:
ogmios:
condition: service_healthy
healthcheck:
test: ['CMD', '/scripts/is-db-synced.sh']
interval: 5s
timeout: 1s
retries: 120
start_period: 100ms
image: ghcr.io/intersectmbo/cardano-db-sync:${CARDANO_DB_SYNC_VERSION:-13.1.0.2}
restart: on-failure
stop_signal: SIGINT
volumes:
- db-sync-data:/var/lib/cexplorer
- node-ipc:/node-ipc
- ../../packages/e2e/local-network/scripts:/scripts

cardano-smash:
<<:
Expand All @@ -142,7 +133,7 @@ services:
SMASH_PASSWORD: ${SMASH_PASSWORD:-change_m}
depends_on:
cardano-db-sync:
condition: service_healthy
condition: service_started
ports:
- ${SMASH_PORT:-3100}:3100
restart: on-failure
Expand Down Expand Up @@ -214,8 +205,6 @@ services:
STAKE_POOL_PROVIDER_URL: http://provider-server:3000/
METADATA_FETCH_MODE: ${METADATA_FETCH_MODE:-smash}
SMASH_URL: ${SMASH_URL:-http://cardano-smash:3100/api/v1}
healthcheck:
test: ['CMD-SHELL', 'curl -s --fail http://localhost:3003/v1.0.0/health']
ports:
- ${PG_BOSS_PORT:-4003}:3003

Expand Down Expand Up @@ -254,12 +243,6 @@ services:
- *sdk-environment
POSTGRES_DB_FILE: /run/secrets/postgres_db_asset
PROJECTION_NAMES: asset
healthcheck:
test:
[
'CMD-SHELL',
'test `curl -fs http://localhost:3000/v1.0.0/health | jq -r ".services[0].projectedTip.blockNo"` -gt 1'
]
ports:
- ${ASSET_PROJECTOR_PORT:-4006}:3000

Expand All @@ -275,12 +258,6 @@ services:
- *sdk-environment
POSTGRES_DB_FILE: /run/secrets/postgres_db_handle
PROJECTION_NAMES: handle
healthcheck:
test:
[
'CMD-SHELL',
'test `curl -fs http://localhost:3000/v1.0.0/health | jq -r ".services[0].projectedTip.blockNo"` -gt 1'
]
ports:
- ${HANDLE_PROJECTOR_PORT:-4004}:3000

Expand All @@ -296,12 +273,6 @@ services:
- *sdk-environment
POSTGRES_DB_FILE: /run/secrets/postgres_db_stake_pool
PROJECTION_NAMES: stake-pool,stake-pool-metadata-job,stake-pool-metrics-job,stake-pool-rewards-job
healthcheck:
test:
[
'CMD-SHELL',
'test `curl -fs http://localhost:3000/v1.0.0/health | jq -r ".services[0].projectedTip.blockNo"` -gt 1'
]
ports:
- ${STAKE_POOL_PROJECTOR_PORT:-4002}:3000

Expand Down
2 changes: 0 additions & 2 deletions packages/cardano-services/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.9'

x-logging: &logging
logging:
driver: 'json-file'
Expand Down
6 changes: 1 addition & 5 deletions packages/e2e/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.9'

x-logging: &logging
logging:
driver: 'json-file'
Expand Down Expand Up @@ -68,9 +66,6 @@ services:
- ./local-network/config/network:/config

cardano-smash:
depends_on:
cardano-db-sync:
condition: service_healthy
volumes:
- ./local-network/config/network:/config

Expand Down Expand Up @@ -113,6 +108,7 @@ services:
stake-pool-projector:
environment:
METADATA_JOB_RETRY_DELAY: 60
POOLS_METRICS_INTERVAL: '50'

volumes:
sdk-ipc:
Expand Down
5 changes: 3 additions & 2 deletions packages/e2e/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ module.exports = {
project('pg-boss'),
project('projection'),
project('providers'),
project('wallet'),
project('wallet_epoch_0'),
project('wallet_epoch_3'),
{
...commonProjectProps,
displayName: 'wallet-real-ada',
testMatch: [`<rootDir>/test/wallet/PersonalWallet/(${realAdaTestFileNames.join('|')}).test.ts`]
testMatch: [`<rootDir>/test/wallet*/PersonalWallet/(${realAdaTestFileNames.join('|')}).test.ts`]
},
{
...commonProjectProps,
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/local-network/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN apt-get update -y && \
apt-get install -y tzdata ca-certificates jq coreutils curl wget

HEALTHCHECK --interval=5s --timeout=1s --retries=200 --start-period=100ms \
CMD /root/scripts/get-epoch.sh | awk '{ if ($0 >= "3") exit 0; else exit 1}'
CMD test -e /root/network-files/run/healthy

STOPSIGNAL SIGINT
COPY --from=builder /build/cardano-node /opt/cardano-node
Expand Down
24 changes: 0 additions & 24 deletions packages/e2e/local-network/scripts/is-db-synced.sh

This file was deleted.

8 changes: 8 additions & 0 deletions packages/e2e/local-network/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ here="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)"
root="$(cd "$here/.." && pwd)"
cd "$root"

healthy() {
sleep 20
touch ./network-files/run/healthy
}

export PATH=$PWD/bin:$PATH

source ./scripts/nodes-configuration.sh
Expand All @@ -21,6 +26,7 @@ trap 'kill 0' INT
echo "Run"
./scripts/make-babbage.sh
./network-files/run/all.sh &
healthy &

for ID in ${SP_NODES_ID}; do
if [ -f "./scripts/pools/update-node-sp$ID.sh" ]; then # Only update the pool if a script exists for that pool.
Expand All @@ -34,4 +40,6 @@ CARDANO_NODE_SOCKET_PATH=$PWD/network-files/node-sp1/node.sock ./scripts/mint-to
CARDANO_NODE_SOCKET_PATH=$PWD/network-files/node-sp1/node.sock ./scripts/setup-wallets.sh
CARDANO_NODE_SOCKET_PATH=$PWD/network-files/node-sp1/node.sock ./scripts/mint-handles.sh

touch ./network-files/run/done

wait
11 changes: 11 additions & 0 deletions packages/e2e/local-network/scripts/wait-local-network-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -euo pipefail

while ! docker exec -i local-network-e2e-local-testnet-1 test -e /root/network-files/run/done 2> /dev/null ; do
echo Waiting...
sleep 10
done

echo Local network init completed
sleep 10
7 changes: 5 additions & 2 deletions packages/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"test:ogmios": "jest -c jest.config.js --forceExit --selectProjects ogmios --runInBand --verbose",
"test:pg-boss": "jest -c jest.config.js --forceExit --selectProjects pg-boss --runInBand --verbose",
"test:providers": "jest -c jest.config.js --forceExit --selectProjects providers --runInBand --verbose",
"test:wallet": "jest -c jest.config.js --forceExit --selectProjects wallet --runInBand --verbose",
"test:wallet": "yarn wait-for-network-init ; yarn test:wallet:0 && { yarn wait-for-network-epoch-3 ; yarn test:wallet:3 ; }",
"test:wallet:0": "jest -c jest.config.js --forceExit --selectProjects wallet_epoch_0 --runInBand --verbose",
"test:wallet:3": "jest -c jest.config.js --forceExit --selectProjects wallet_epoch_3 --runInBand --verbose",
"test:wallet-real-ada": "NETWORK_SPEED=slow jest -c jest.config.js --forceExit --selectProjects wallet-real-ada --runInBand --verbose",
"test:web-extension:build:sw": "tsc --build ./test && tsc --build ./test/web-extension && webpack -c test/web-extension/webpack.config.sw.js",
"test:web-extension:build:other": "tsc --build ./test && tsc --build ./test/web-extension && webpack -c test/web-extension/webpack.config.js",
Expand Down Expand Up @@ -70,7 +72,8 @@
"test:debug": "DEBUG=true yarn test",
"generate-mnemonics": "ts-node src/scripts/mnemonic.ts",
"multi-delegation-data-gen": "ts-node src/tools/multi-delegation-data-gen/index.ts",
"wait-for-network": "ts-node src/scripts/is-local-network-ready.ts"
"wait-for-network-epoch-3": "DB_SYNC_CONNECTION_STRING='postgresql://postgres:doNoUseThisSecret!@localhost:5435/cexplorer' ts-node src/scripts/is-local-network-ready.ts",
"wait-for-network-init": "local-network/scripts/wait-local-network-init.sh"
},
"repository": "https://github.com/input-output-hk/cardano-js-sdk",
"license": "Apache-2.0",
Expand Down
12 changes: 4 additions & 8 deletions packages/e2e/src/scripts/is-local-network-ready.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
import { Pool, QueryResult } from 'pg';
import { Pool } from 'pg';

const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

Expand All @@ -21,13 +21,9 @@ const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
while (!isReady && currentElapsed < waitTime) {
try {
console.log('Waiting...');
const inputsResults: QueryResult<{ no: number }> = await db.query(
'select epoch.no from epoch order by epoch.no DESC limit 1'
);
const inputsResults = await db.query<{ no: number }>('SELECT no FROM epoch ORDER BY no DESC LIMIT 1');

isReady = inputsResults.rows[0].no >= 4; // One more than the local network healthcheck
} catch {
// continue
isReady = inputsResults.rows[0].no >= 3;
} finally {
currentElapsed = Date.now() / 1000 - start;
await sleep(5000);
Expand All @@ -39,5 +35,5 @@ const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
return -1;
}

console.log('Local network ready!');
console.log('Local network reached epoch 3');
})().catch(console.log);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseWallet } from '@cardano-sdk/wallet';
import { Cardano, StakePoolProvider } from '@cardano-sdk/core';
import { buildSharedWallets } from '../wallet/SharedWallet/ultils';
import { buildSharedWallets } from '../wallet_epoch_0/SharedWallet/utils';
import { filter, firstValueFrom, map, take } from 'rxjs';
import {
getEnv,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseWallet } from '@cardano-sdk/wallet';
import { Cardano } from '@cardano-sdk/core';
import { buildSharedWallets } from './ultils';
import { buildSharedWallets } from './utils';
import { filter, firstValueFrom, map, take } from 'rxjs';
import {
getEnv,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
walletReady,
walletVariables
} from '../../../src';
import { buildSharedWallets } from './ultils';
import { buildSharedWallets } from '../../wallet_epoch_0/SharedWallet/utils';
import { combineLatest, filter, firstValueFrom, map, take } from 'rxjs';
import { logger } from '@cardano-sdk/util-dev';

Expand Down

0 comments on commit 3923bbf

Please sign in to comment.