Skip to content

Refactor cache invalidation test #796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ ARG UBUNTU_VERSION=20.04
FROM ubuntu:${UBUNTU_VERSION} as ubuntu-nodejs
ARG NODEJS_MAJOR_VERSION=14
ENV DEBIAN_FRONTEND=nonintercative
RUN apt-get update && apt-get install curl -y &&\
curl --proto '=https' --tlsv1.2 -sSf -L https://deb.nodesource.com/setup_${NODEJS_MAJOR_VERSION}.x | bash - &&\
apt-get install nodejs -y
RUN apt-get update && apt-get install curl -y
RUN curl --proto '=https' --tlsv1.2 -sSf -L https://deb.nodesource.com/setup_${NODEJS_MAJOR_VERSION}.x | bash -
RUN curl --proto '=https' --tlsv1.2 -sSf -L https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - &&\
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list
RUN apt-get update
RUN apt-get install nodejs -y
RUN apt-get install -y --no-install-recommends ca-certificates jq postgresql-client

FROM ubuntu-nodejs as nodejs-builder
RUN curl --proto '=https' --tlsv1.2 -sSf -L https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - &&\
Expand Down Expand Up @@ -59,10 +63,6 @@ COPY --from=cardano-services-builder /app/packages/util-rxjs/package.json /app/p

FROM cardano-services as provider-server
ARG NETWORK=mainnet
RUN curl --proto '=https' --tlsv1.2 -sSf -L https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - &&\
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list &&\
apt-get update && apt-get install -y --no-install-recommends \
ca-certificates jq
ENV \
CARDANO_NODE_CONFIG_PATH=/config/cardano-node/config.json \
NETWORK=${NETWORK}
Expand Down Expand Up @@ -94,7 +94,6 @@ WORKDIR /app/packages/cardano-services
CMD ["node", "dist/cjs/cli.js", "start-pg-boss-worker"]

FROM cardano-services as projector
RUN apt-get update && apt-get install -y --no-install-recommends jq postgresql-client
WORKDIR /
COPY compose/projector/init.* ./
RUN chmod 755 init.sh
Expand Down
2 changes: 2 additions & 0 deletions packages/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@
"buffer": "^6.0.3",
"chromedriver": "^114.0.0",
"copy-webpack-plugin": "^10.2.4",
"dockerode": "^3.3.1",
"dockerode-utils": "^0.0.7",
"eslint": "^7.32.0",
"events": "^3.3.0",
"expect-webdriverio": "^3.2.1",
Expand Down
77 changes: 64 additions & 13 deletions packages/e2e/test/long-running/cache-invalidation.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable max-statements */
import { AddressType, KeyRole } from '@cardano-sdk/key-management';
import { Cardano } from '@cardano-sdk/core';
import {
Expand All @@ -13,24 +12,72 @@ import {
walletReady,
walletVariables
} from '../../src';
import { containerExec } from 'dockerode-utils';
import { getRandomPort } from 'get-port-please';
import { logger } from '@cardano-sdk/util-dev';
import Docker from 'dockerode';
import path from 'path';

const env = getEnv(walletVariables);
const vrf = Cardano.VrfVkHex('2ee5a4c423224bb9c42107fc18a60556d6a83cec1d9dd37a71f56af7198fc759');

const wallet1Params: KeyAgentFactoryProps = {
accountIndex: 0,
chainId: env.KEY_MANAGEMENT_PARAMS.chainId,
mnemonic:
// eslint-disable-next-line max-len
'phrase raw learn suspect inmate powder combine apology regular hero gain chronic fruit ritual short screen goddess odor keen creek brand today kit machine',
passphrase: 'some_passphrase'
};

describe('cache invalidation', () => {
let testProviderServer: Docker.Container;
let wallet1: TestWallet;

beforeAll(async () => {
const port = await getRandomPort();

// Get environment from original provider server container
const docker = new Docker();
const originalProviderServer = docker.getContainer('local-network-e2e-provider-server-1');
const cmdOutput = await containerExec(originalProviderServer, [
'node',
'-e',
'console.log(`sdk_token${JSON.stringify(process.env)}sdk_token`)'
]);
const matchResult = cmdOutput[0].match(/sdk_token(.*)sdk_token/);

if (!matchResult) throw new Error('Error getting original container environment');

const [, encodedEnv] = matchResult;

const Env = Object.entries({
...JSON.parse(encodedEnv),
DISABLE_DB_CACHE: 'false',
LOGGER_MIN_SEVERITY: 'debug'
}).map(([key, value]) => `${key}=${value}`);

const network = docker.getNetwork('local-network-e2e_default');

// Test container
testProviderServer = await docker.createContainer({
Env,
HostConfig: {
Binds: [`${path.join(__dirname, '..', '..', '..', '..', 'compose', 'placeholder-secrets')}:/run/secrets`],
PortBindings: { '3000/tcp': [{ HostPort: port.toString() }] }
},
Image: 'local-network-e2e-provider-server',
name: 'local-network-e2e-provider-server-test'
});

await network.connect({ Container: testProviderServer.id });
await testProviderServer.start();

const override = Object.fromEntries(
Object.entries(process.env)
.filter(([key]) => walletVariables.includes(key as typeof walletVariables[number]))
.map(([key, value]) => [key, value?.replace('localhost:4000/', `localhost:${port}/`)])
);
const env = getEnv(walletVariables, { override });
const wallet1Params: KeyAgentFactoryProps = {
accountIndex: 0,
chainId: env.KEY_MANAGEMENT_PARAMS.chainId,
mnemonic:
// eslint-disable-next-line max-len
'phrase raw learn suspect inmate powder combine apology regular hero gain chronic fruit ritual short screen goddess odor keen creek brand today kit machine',
passphrase: 'some_passphrase'
};

jest.setTimeout(180_000);

wallet1 = await getWallet({
Expand All @@ -45,9 +92,13 @@ describe('cache invalidation', () => {
await waitForWalletStateSettle(wallet1.wallet);
});

afterAll(() => wallet1.wallet.shutdown());
afterAll(async () => {
wallet1.wallet.shutdown();
await testProviderServer.stop();
await testProviderServer.remove();
});

test.skip('cache is invalidated on epoch rollover', async () => {
test('cache is invalidated on epoch rollover', async () => {
const wallet = wallet1.wallet;

await walletReady(wallet);
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2587,6 +2587,8 @@ __metadata:
convict: ^6.2.4
copy-webpack-plugin: ^10.2.4
delay: 5.0.0
dockerode: ^3.3.1
dockerode-utils: ^0.0.7
dotenv: ^16.0.1
envalid: ^7.3.1
eslint: ^7.32.0
Expand Down